Hello,
I show a panel with scroll and a table inside. I want the table be
completely visible in the panel,
so I try to resize the panel in order to get this objective. However,
what I get is a panel with very
little dimensions (I don't even see the table inside), and I must resize
it manually for the first time.
I post the relevant piece of code. I do some things a bit strange
(because I've tried a lot of things and
I don't get the panel with the desired size). 'redimensionColumns' is a
method of my own that changes the
size of the columns in the table to contain all the text in them.
I hope you can give me some hint or idea to solve this problem, since
I'm very confused.
Thanks a lot
tableView = new JTable(dataModel);
tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tableView.setDefaultRenderer(java.lang.String.class, new
MyRenderer());
JTableHeader header = tableView.getTableHeader();
header.setReorderingAllowed(false);
tableView.setColumnSelectionAllowed(false);
tableView.setRowSelectionAllowed(false);
tableView.setCellSelectionEnabled(false);
redimensionColumns();
JPanel panel = new JPanel();
// Strange things to get my objective.
Dimension originalPanelDimension = (Dimension) panel.getSize();
int MARGIN = 5;
int MAXIMUM_HORIZONTAL = 200;
int MAXIMUM_VERTICAL = 500;
Dimension maximumPanelDimension = new Dimension(
Math.min((int) originalPanelDimension.getWidth() + MARGIN,
MAXIMUM_HORIZONTAL),
Math.min((int) originalPanelDimension.getHeight() + MARGIN,
MAXIMUM_VERTICAL));
JScrollPane scrollpane = new JScrollPane(panel);
panel.setLayout(new BoxLayout(panel, (BoxLayout.Y_AXIS)));
panel.add(tableView.getTableHeader());
panel.add(tableView);
scrollpane.setMinimumSize(maximumPanelDimension);
panel.setMinimumSize(maximumPanelDimension);
getContentPane().add(scrollpane);
pack(); // Commenting this line not solves the problem.
show();
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing