我尝试将JTable
的列宽设置为timeLineDialog
占总数的百分比。我被停止了,因为getWidth()
返回 0 。
dialog.add(header,BorderLayout.NORTH);
dialog.add(timeLineDialog,BorderLayout.CENTER);
int panelSize=timeLineDialog.getWidth();
System.out.println("total width="+Integer.toString(panelSize));
for (int i=0; i<percentWidths.length; i++) {
System.out.println("setting column "+Integer.toString(i)+" to "+Integer.toString((int) Math.round(panelSize*percentWidths[i])));
timeLineDialog.getColumnModel().getColumn(i).setPreferredWidth((int) Math.round(panelSize*percentWidths[i]));
}
timeLineDialog.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
dialog.add(footer,BorderLayout.SOUTH);
dialog.pack();
dialog.setVisible(true);
调试输出显示panelSize=0
。如何获得JTable
的宽度? TIA。