Skip to content
Advertisement

Misaligned box in box layout when adding JScrollpane

I wanted to create a simple table with the some of the features of a JTable, but easier to style, so I created a couple of boxes in a box layout, one for the header and another to contain the cells. When I added the JScrollPane to the cell’s box, it indented the header box and now the don’t line up.

Misaligned box:

https://i.stack.imgur.com/hKGk7.png

I’ve tried setAlignmentX and ComponentOrientation, but not luck. Does anyone have any ideas?

JavaScript

Advertisement

Answer

I’ve tried setAlignmentX

That is only relevant for the components that you add to the panel using the vertical BoxLayout:

JavaScript

You set the alignment on the headersBox, but not the scrollPane. So you are missing:

JavaScript

Also

JavaScript

is not needed, since this is the parent panel, not a child component.

and,

JavaScript

is not needed, since left alignment is not relevant for a horizontal layout.

and,

JavaScript

is not needed since this component is added to the scroll pane

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement