我想在JScrollPane中设置一个具有固定num宽度的JTable的每一列,但我不能用infoTable.getColumnModel().getColumn(0).setPreferredWidth(10);
我使用JScrollPane的默认布局,并在j2se 1.4中添加带有scrollPane的setViewPortView(infoTable)的表.
我怎么能这样做?
这是我的代码
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
public TableFrame() {
jScrollPane1 = new javax.swing.JScrollPane();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(0, 0, 0)));
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
this.setSize(new Dimension(600, 600));
this.jScrollPane1.setSize(500, 500);
this.getContentPane().add(this.jScrollPane1, BorderLayout.CENTER);
this.getContentPane().add(this.jButton1, BorderLayout.WEST);
table = new JTable(new javax.swing.table.DefaultTableModel(100, 2));
this.jScrollPane1.setViewportView(table);
table.getColumnModel().getColumn(0).setWidth(10);
}
PS.回答的问题我需要拖动列来调整大小,所以我无法设置最大和最小尺寸