Reputation: 69
Is there any method in java that lets me place a table in the center of the panel...
This is the code:
if(entp.isSelected() ){
students = new DefaultTableModel();
table.setVisible(true);
table1.setVisible(false);
table2.setVisible(false);
table3.setVisible(false);
table4.setVisible(false);
...
}
I'm importing this libraries:
import javax.swing.; import java.awt.; import java.awt.event.; import java.sql.; import javax.swing.table.*;
and I need to place the called table,,,so table in this case in the center of the panel..
Help me plz:(
Upvotes: 0
Views: 1924
Reputation: 3113
Look up Layout Managers, specifically BorderLayout.
JPanel panel = new JPanel(new BorderLayout());
JTable table = new JTable(tableModel);
panel.add(table, BorderLayout.CENTER);
The table table
is centered in panel
.
(I'm assuming you're using Swing. If not, add your UI library as a tag and mention it in your post.)
Upvotes: 3