我希望在JFrame
的底部有按鈕btn
。我有這個在右側。我的代碼中的錯誤在哪裏?Swing組件的位置不正確
class MainClass extends JFrame {
private JSplitPane splitPan=null;
private void treePanel(){
DefaultMutableTreeNode nod=new DefaultMutableTreeNode("AAA",true);
nod.add(new DefaultMutableTreeNode("abcd"));
JTree tree=new JTree(nod);
JScrollPane scroll=new JScrollPane(tree);
splitPan=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scroll,new JLabel("aaaaa"));
splitPan.setSize(this.getMaximumSize());
add(splitPan);
}
public MainClass() {
setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
treePanel();
add(new JButton("btn"));
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300,200);
setVisible(true);
}
}
簡單/漂亮/實例1 – mKorbel 2012-02-13 11:06:34