我是 MigLayout 的初学者,所以我需要在一个 JPanel 中添加多个 JTable,但是当我尝试添加多个表时,只会出现最后一个表,而其他表只标记为 JScrollPane 边框。我的代码在下面。
Test() {
//Panels
JPanel globalPanel = new JPanel(new MigLayout("fillx","[]","[]50[]"));
JPanel topPanel = new JPanel (new MigLayout("fillx","40px[]15[grow]","40px[]"));
JPanel tablePanel = new JPanel (new MigLayout("fillx","[center]","[]"));
//Components
JComboBox boxProj;
JTable table;
JScrollPane scroll;
//Top Panel
topPanel.add(new JLabel("Project Name:"));
String listString[] = {"test"};
boxProj= new JComboBox(listString);
topPanel.add(boxProj);
//Table Panel
//Tables
table = new JTable();
createTable(table); //my table
//Adding Multiples Tables
tablePanel.add( new JScrollPane(table),"growx,wrap,hmax 300");
tablePanel.add( new JScrollPane(table),"growx,wrap,hmax 300");
//Scroll to TablePanel
scroll = new JScrollPane(tablePanel);
scroll.setBorder(BorderFactory.createTitledBorder(null, "Project", TitledBorder.LEFT, TitledBorder.TOP, new Font("null", Font.BOLD, 12), Color.BLACK));
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//Global Panel
globalPanel.add(topPanel, "dock north");
JSeparator separator = new JSeparator();
globalPanel.add(separator,"growx");
globalPanel.add(scroll,"dock south, growx");
getContentPane().add(globalPanel);
pack();
setSize(1024,768);
}
如果我犯了一些错误,请纠正我。
谢谢!!