2016-07-06 3 views
0

私が作っているツールのための非常に基本的なGUIを作成し、私は異常な問題に遭遇しました。基本的な考え方は、JListとJTableを作成してJSplitPane内に配置することです。その分割ペインはJFrame内のほとんどの領域を占めますが、分割ペインの下にも同じJFrame内にあるボタンがいくつかあります。私が望むデザインを達成するために、私はボタンのための水平ボックスと、分割ペインのための垂直ボックスと水平ボタンボックスを使用しています。スプリットペインをデザインし、必要に応じて動作させていたので、ボタンをJFrameに追加する調整を始めました。私が修正を行ったとき、ボタンは分割ペインの下の正しい場所にありましたが、分割ペインの左側にゴースト成分がありました。私はその何かがシンプルで愚かだと確信していますが、私はどこに間違っているのか分かりません。それはどのように見えるのいくつかの写真があります。JFrame内の水平スクロールゴーストコンポーネント - JSplitPane

これは、分割ペインがどのように見えるかを示しています。 Split Pane only

これは、ボックスとボタンが追加された様子です。 Boxes and Buttons

分割ペインの左側の空白を取り除こうとしています。

これは、関連するコードです:

リストがJListのテーブルで、viewTableがJTables

list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
    list.setSelectedIndex(0); 
    list.addListSelectionListener(this); 
    listScroll = new JScrollPane(list); 
    viewTable = table; 
    columnModel = viewTable.getColumnModel(); 
    for(int i = 0;i<columnModel.getColumnCount();i++) 
     columnModel.getColumn(i).setMinWidth(150); 
    viewTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 
    dataScroll = new JScrollPane(viewTable,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 
    dataScroll.getHorizontalScrollBar().setUnitIncrement(150); 

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,listScroll,dataScroll); 

    JFrame viewFrame = new JFrame("View/Delete"); 
    viewFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    JButton deleteButton, revertButton, viewCancelButton; 
    Box viewBox = Box.createVerticalBox(); 
    Box ButtonBox = Box.createHorizontalBox(); 
    viewCancelButton = new JButton("Cancel"); 
    viewCancelButton.addActionListener(this); 
    revertButton = new JButton("Revert Changes"); 
    revertButton.addActionListener(this); 
    deleteButton = new JButton("Delete"); 
    deleteButton.addActionListener(this); 
    ButtonBox.add(viewCancelButton); 
    ButtonBox.add(Box.createRigidArea(new Dimension(30,0))); 
    ButtonBox.add(revertButton); 
    ButtonBox.add(Box.createRigidArea(new Dimension(30,0))); 
    ButtonBox.add(deleteButton); 
    viewBox.removeAll(); 
    viewBox.add(splitPane); 
    viewBox.add(Box.createRigidArea(new Dimension(0,30))); 
    viewBox.add(ButtonBox); 
    viewBox.add(Box.createRigidArea(new Dimension(0,30))); 
    viewBox.setVisible(true); 
    viewFrame.add(viewBox); 
    viewFrame.pack(); 
    viewFrame.setVisible(true); 
助けを事前に

感謝です!これ以上の情報が必要な場合はお知らせください。アドバイスは大歓迎です。

+0

垂直ボックスに追加する前に、JSplitPaneを 'BorderLayout'を含む' JPanel'にラップします。 – copeg

+0

パーフェクト!迅速な答えをありがとう。 – Evan

答えて

2

JSplitPaneをに含めると、BorderLayoutが含まれ、縦のボックスに追加されます。結果がどのように異なるかは、各レイアウトマネージャ(BoxLayoutとBorderLayout)がどのように子コンポーネントのサイズを管理するかと関係しています。

関連する問題