2016-07-03 12 views
1

私のコードはJPanelJTabelです。私は現在、サイズ変更の問題に遭遇しています。それはちょうどGUIのWESTを占めており、私はそれが左下を占めるようにしようとしています。JPanelにあるJTableのサイズを変更

public void table(JFrame f) 
{ 

    String[] columnNames = {"First Name", "Last Name"}; 

    Object[][] players = { 
        {"John", "Doe"}, 
        {"Steve", "White"} 
    }; 

    JTable table = new JTable(players, columnNames); 
    JScrollPane scrollPane = new JScrollPane(table); 

    table.setFillsViewportHeight(true); 

    JPanel container = new JPanel(); 
    container.setPreferredSize(new Dimension(50,300)); //This seems very wrong 
    container.setLayout(new BorderLayout()); 
    container.add(table.getTableHeader(), BorderLayout.PAGE_START); 
    container.add(table, BorderLayout.WEST); 

    f.add(container); 

    f.revalidate(); 

答えて

0

container.add(table.getTableHeader(), BorderLayout.PAGE_START); 

あなたはBorderLayout.PAGE_START、と言うのコード行で:ここに私のコードです。 PAGE_STARTの代わりに、下の図の助けを借りてコンポーネントを配置する場所に定義する必要があります。

enter image description here

詳細については、あなたが読むことができるthis

関連する問題