Reputation: 2049
I have to create a search textField
object above a JTable
. This JTable is inside a JScrollPane
:
To reach my target I implement a Jpanel where I add the JTextField
and the Jtable
:
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);
In this way I get the following result:
Upvotes: 1
Views: 257
Reputation: 3956
Default layout for JPanel
is FlowLayout
. So you must set your panel's layout to BorderLayaout
.
Change this
JPanel panel = new JPanel();
with
JPanel panel = new JPanel(new BorderLayout());
Upvotes: 2