Hi,
not everything has to use GroupLayout. Since you already have three
tables in a JPanel, you can let that JPanel use any other layout manager
which you prefer for the usercase.
And yes, you could also write the code for the panel with the tables in
it by hand if that is easier and still add the panel to other forms
using the gui builder - like lego.
Most windows in NetBeans itself were made using the gui builder, but
here and there you will find custom code building forms where it makes
sense.
-mbien
On 22.02.24 22:09, Joseph Huber wrote:
Hello,
I am modifying a small application that was designed with the NetBeans
GUI builder. One of the JPanels displays three JTables side-by-side.
The JTables have three columns and are inside of individual
JScrollPanes. My task is to add more tables to display additional
data. The JTable columns were very wide, in order to fully display
the widest expected data. Unfortunately, this often leaves much dead
space in the tables that could be reclaimed to display more tables.
I have modified the JTables to nicely adjust their column widths to
match the actual data, but I cannot get the JScrollPanes to shrink
down to the width of the optimized JTables. Thus, there is often a
bunch of wasted empty white space in the JScrollPanes. After the data
is added to the table, table.getPreferredScrollableViewportSize()
correctly reports the size of the viewport to display the optimized
table, but I cannot figure out how to change the JScrollPane width
from the size that it is set to in the GUI Designer to match the
viewport size requested by the JTable; scrollpane.setSize() and
scrollpane.setPreferredSize() don’t seem to have any effect. It seems
that the upstream Swing objects aren’t querying the JTables for
display information after the data is added.
Internet search indicates that (in addition to a general disdain for
GUI builders) this may be due to the GroupLayout layout manager used
by the NetBeans GUI builder or some other limitations of how layout is
done in the GUI Builder. Any thoughts on how to get the JScrollPane
to resize?
My second challenge would be making this JPanel horizontally
scrollable. Even using JTables with optimized column widths, with the
number of tables I have to add, the JPanel would end up wider than a
feasible desktop window size. I tried adding the
JTables/JScrollPanels into one larger JScrollPanel with the GUI
Builder, but the GUI Builder does not seem to be able to do that.
Is it feasible to do what I need to do with the NetBeans GUI builder,
or do I need to scrap the existing GUI Builder JPanel and switch to a
manually coded/designed JPanel?
Thank You!
Joe Huber
Standard Refrigeration LLC