I would like the table to have a fixed width and that the height should resize itself up to filling the panel.
and
I have a BoxLayout (in a panel of a BorderLayout) in which I've put a JTable and a button vertically.
there are three (mentioned only simple) ways
use built_in
LayoutManager
forJPanel
-FlowLayout
(FLowLayout.CENTER
),override
FLowLayout.LEFT
orRIGHT
in the case that you want to aling,JComponent
laid byFlowLayout
never will be resizable without programatically to changeXxxSize
and notified byrevalidate
&repaint
,set proper size for JScrollPane by override
JTable.setPreferredScrollableViewportSize(new Dimension(int, int));
,JScrollPane accepts this Dimension as initial size, required is usage of
JFrame.pack(
), beforeJFrame.setVisible(true)
BoxLayout
acceptsmin, max and preferred size
, override all these three sizes forJScrollPane
(
half solution, but most comfortable
) changeLayoutManager
forJPanel
toBorderLayout
,put
JScrollPane
withJTable
toBorderLayout.EAST/WEST
area,then override
JTable.setPreferredScrollableViewportSize(new Dimension(int, int));
,JScrollPane
will occupy whole area forBorderLayout.EAST/WEST
and will be resizeable only onheights
coordinates
- use
MigLayout
, here are a few posts aboutMigLayout
andJScrollPane
(withJTextArea
,JTable
)