wrong size of JScrollPane
Hello, the pieces of my code:
- my frame is set to: Code:
frame.setMinimumSize(new Dimension(640, 480));
frame.setPreferredSize(new Dimension(640, 480));
frame.setResizable(false);
frame.setLocation(100, 100);
- within frame is panel with padding: Code:
JPanel panel = new JPanel(new BorderLayout());
JPanel topPadding = new JPanel();
topPadding.setPreferredSize(new Dimension(0, 15));
panel.add(topPadding, BorderLayout.PAGE_START);
JPanel bottomPadding = new JPanel();
bottomPadding.setPreferredSize(new Dimension(0, 30));
panel.add(bottomPadding, BorderLayout.PAGE_END);
JPanel leftPadding = new JPanel();
leftPadding.setPreferredSize(new Dimension(50, 0));
panel.add(leftPadding, BorderLayout.LINE_START);
JPanel rightPadding = new JPanel();
rightPadding.setPreferredSize(new Dimension(50, 0));
panel.add(rightPadding, BorderLayout.LINE_END);
- the last area is missing - BorderLayout.CENTER and this is my problem: Code:
JTable table = new JTable(10, 4);
table.setFillsViewportHeight(true);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane area = new JScrollPane(table);
area.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
panel.add(area, BorderLayout.CENTER);
- the rest of my code is fully functional and tested, but the problem is... if I put this piece of code instead of previous: Code:
JScrollPane area = new JScrollPane(); // this piece instead of JScrollPane area = new JScrollPane(table);
everything is correct... frame will stay 640x480... when I use previous version (with table), frame will change its size to 650xMUCH_MORE_THAN_480... I've tried almost everything I've found and I don't know what the solution is... I tried print dimensions of table (viewport of scroll pane): Code:
System.out.println(area.getViewport().getViewSize());
and it prints Code:
java.awt.Dimension[width=530,height=160]
so I think, something is wrong... I did some error :confused: ... any advice? Thnx