我有一个createUI()函数,它将JPanel加载到NORTH,SOUTH,EAST。Java Swing:相对定位和自动调整大小?
private void createUI() {
add(createToolBar(), BorderLayout.NORTH);
add(createDataView(), BorderLayout.SOUTH);
add(createHistoryView(), BorderLayout.EAST);
createMenuBar();
setTitle("My Application");
}
在正确的位置。每个部件显示,但是,它们都在固定大小的JPanel。我想知道是否可以让JPanel完全填充BorderLayout区域。
例如,createDataView()是一个带有表格的简单Jpanel。我希望它水平扩展,并有一个固定的高度。
private JPanel createDataView(){
JPanel panel = new JPanel();
String data[][] = {{"001","vinod","Bihar","India","Biology","65","First"},
{"002","Raju","ABC","Kanada","Geography","58","second"},
{"003","Aman","Delhi","India","computer","98","Dictontion"},
{"004","Ranjan","Bangloor","India","chemestry","90","Dictontion"},
{"004","Ranjan","Bangloor","India","chemestry","90","Dictontion"}};
String col[] = {"Roll","Name","State","country","Math","Marks","Grade"};
JTable table = new JTable(data,col);
table.setPreferredScrollableViewportSize(new Dimension(900,100));
JTableHeader header = table.getTableHeader();
header.setBackground(Color.yellow);
JScrollPane pane = new JScrollPane(table);
table.setAutoResizeMode(JTable.WIDTH);
table.doLayout();
panel.add(pane);
return panel;
}
现在我正在依靠手动设置尺寸。但是,我会想办法获取当前窗口宽度,并将其设置为如下所示。
table.setPreferredScrollableViewportSize(new Dimension(900,100));
你有两件东西塞进南方“细胞”......那些应该看起来相互关联的人是怎么样的? – 2010-10-05 20:00:10
添加了一些更多详细信息... – KJW 2010-10-05 20:22:10