我在 java swing 中创建了一个应用程序,在其中JInternalFrame
单击JFrame
. internalFrame 由具有 32 列的表组成,其中动态添加值。
问题是,当我们点击按钮时JInternalFrame
,加载会有点延迟。代码中的循环是否会导致延迟
谁能告诉我一些解决方案以防止加载延迟...
public class AttendanceView extends javax.swing.JInternalFrame {
private int count=0;
String []columnNames={"<html><b>Name</b></html>","<html><b>1</b></html>","<html><b>2</b></html>",""
+ "<html><b>3</b></html>",""+ "<html><b>4</b></html>",""
+ "<html><b>5</b></html>",""+ "<html><b>6</b></html>",""
+ "<html><b>7</b></html>",""+ "<html><b>8</b></html>",""
+ "<html><b>9</b></html>",""+ "<html><b>10</b></html>",""
+ "<html><b>11</b></html>",""+ "<html><b>12</b></html>",""
+ "<html><b>13</b></html>",""+ "<html><b>14</b></html>",""
+ "<html><b>15</b></html>",""+ "<html><b>16</b></html>",""
+ "<html><b>17</b></html>",""+ "<html><b>18</b></html>",""
+ "<html><b>19</b></html>",""+ "<html><b>20</b></html>",""
+ "<html><b>21</b></html>",""+ "<html><b>22</b></html>",""
+ "<html><b>23</b></html>",""+ "<html><b>24</b></html>",""
+ "<html><b>25</b></html>",""+ "<html><b>26</b></html>",""
+ "<html><b>27</b></html>",""+ "<html><b>28</b></html>",""
+ "<html><b>29</b></html>",""+ "<html><b>30</b></html>",""
+ "<html><b>31</b></html>"};
String dataValues[][];
public AttendanceView() {
initComponents();
try
{
dataValues=new String[10][32];
int i=0;
for(i=0;i<5;i++)
{
for(int j=0;j<32;j++)
{
if(j==0)
dataValues[i][0]="Manu Suseelan";
else
dataValues[i][j]="<html><body style='background:green;color:green'> ||| </center></html>";
}
}
} catch (Exception ex) {System.out.println("sql error:"+ex);
}
DefaultTableModel df = new DefaultTableModel();
df.setDataVector(dataValues,columnNames);
table.setModel(df);
int index=0;
while (index < 32) {
TableColumn a = table.getColumnModel().getColumn(index);
a.setPreferredWidth(100);
a.setResizable(false);
index++;
}
TableColumn a = table.getColumnModel().getColumn(0);
a.setPreferredWidth(1000);
}
...