用BorderLayout,列可以变宽,高度不会变。 JTable table = new JTable(p, n); table.setPreferredScrollableViewportSize(new Dimension(550, 30)); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this window. f.getContentPane().add(scrollPane, BorderLayout.CENTER); f.setTitle("Simple Table"); f.pack();
JFrame yourFrame ............ JPanel jPanelMain = new JPanel(); BorderLayout borderLayout = new BorderLayout(); JTable jTable = new JTable();yourFrame.setContentPane(jPanelMain); jPanelMain.setLayout(borderLayout); jPanelMain.add(jTable, BorderLayout.CENTER); // or BorderLayout.NORTH BorderLayout.xxxx
table.setPreferredScrollableViewportSize(new Dimension(550, 30));
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this window.
f.getContentPane().add(scrollPane, BorderLayout.CENTER);
f.setTitle("Simple Table");
f.pack();
............
JPanel jPanelMain = new JPanel();
BorderLayout borderLayout = new BorderLayout();
JTable jTable = new JTable();yourFrame.setContentPane(jPanelMain);
jPanelMain.setLayout(borderLayout);
jPanelMain.add(jTable, BorderLayout.CENTER); // or BorderLayout.NORTH BorderLayout.xxxx
试试,不知道可不可行
你可以在监听到 Frame 的大小改变之后,重新计算行/列的高/宽,再为表格重新设置。
我也暂无办法。
还是还有其他组件?还有其他什么?
说清楚点,或许今晚有时间可以帮你看看。
另外如果大家能用监测窗口大小的方法把代码公布出来给大家欣赏一下,让大家共同进步!
试试啊