2016-04-09 12 views
1

のオブジェクトをJTableの上に作成する必要があります。このJTableはJScrollPaneの内側にある: enter image description hereJScrollPaneにJTextField検索バーを配置する

私の目標を達成するために、私は私がJTextFieldを追加し、JtableのJPanelを実装:

JTable table = new JTable(); 
JTextField search = new JTextField(); 
JPanel panel = new JPanel(); 
panel.add(search, BorderLayout.NORTH); 
panel.add(table, BorderLayout.CENTER); 
this.setViewportView(panel); 

私は次のような結果を得る。このように:

enter image description here

答えて

2

JPanelのデフォルトレイアウトはFlowLayoutです。したがって、パネルのレイアウトをBorderLayaoutに設定する必要があります。

JPanel panel = new JPanel(new BorderLayout()); 

変更この

JPanel panel = new JPanel(); 

関連する問題