JTable sizing issue

后端 未结 2 1534
闹比i
闹比i 2021-01-29 01:42

I am having an issue with JTables I know my code is a little hard to follow, it\'s also a little jumbled around because it\'s coming from a fairly big program. And yes I just le

2条回答
  •  执念已碎
    2021-01-29 02:11

    1. JTable can't returns proper Dimension or PreferredSize, there are three ways

    2. table.setPreferredScrollableViewportSize(table.getPreferredSize()); but notice for small JTables with a few Rows and Columns too

    3. to calculate desired size for (part) of Columns and (part) Rows too, then pass this Dimension in form table.setPreferredScrollableViewportSize(new Dimension(x, y));

    4. override getPreferredSize for JScrollPane

    5. then JFrame.pack(before JFrame.setVisible(true)) to calculate desired Size on the screen

    6. JPanel has FlowLayout implemented in API, I'd to suggest to change to BorderLayout, then JScrollPane in CENTER area can fill whole (available) area and will be resizable with JFrame, not possible to resize JComponent (together with its container) layed by FlowLayout

    7. have to call data.revalidate(), data.repaint() and Show.pack() as last code lines instead of (remove this code line) Show.setVisible(true);

    8. rename Show to myFrame and show to myButton

提交回复
热议问题