
tPreferredSize(subPanel.getMinimumSize()) Gbc.fill = GridBagConstraints.HORIZONTAL GridBagConstraints gbc = new GridBagConstraints() For example: JPanel topPanel = new JPanel() If you use it, you can set the anchor to be SOUTH, and the weighty to be 0.0 which should prevent the component from stretching its height and will seat it at the bottom. Myself, I'd use a layout with more "oomph" than FlowLayout for this, such as GridBagLayout. If you use the GridBagLayout, then you will need to play with the constraints of each component. If you use a BoxLayout then you will need to play with the setAlignmentY(.) property of each component. Or if you don't want to use a non JDK class then the BoxLayout or the GridBagLayout would be the way to go. Rl.setAlignment( RelativeLayout.TRAILING ) It can be used as a direct replacement to your existing code: RelativeLayout rl = new RelativeLayout(RelativeLayout.X_AXIS, 0) You could use the Relative Layout to align all the components to the bottom. Or if you are just trying to position all the components on the bottom of the panel then you need to use a different layout manager. Of course this would only work if all the components on the panel have the same baseline.
Flowlayout java put bottom code#
If you are trying to center text on the baseline then maybe you can override the baseline of the panel with code something like: JPanel subPanel = new int getBaseline(int width, int height) I can't tell from your question if you are actually trying to center all the text on the baseline independent of the Font size or whether you are just trying to get all components to be painted at the botton of the panel. The API for the setAlignOnBaseline(.) method states:Ĭomponents that do not have a baseline will be centeredĪ JPanel does not have a reasonable baseline to use since components can be on multiple lines depending on the layout manager being used.
Flowlayout java put bottom how to#
Any ideas how to get the sub JPanels to behave the same? If you run this code you'll notice the top panel has the smaller "Foo"s centered in the panel, while the one on the bottom has the desired 'bottom-aligned' behavior I'm hoping for. ParentPanel.add(bottomPanel, BorderLayout.SOUTH)

ParentPanel.add(topPanel, BorderLayout.NORTH) tAlignmentY(Component.BOTTOM_ALIGNMENT) ītBackground(Color.DARK_GRAY) Private static final Font font2 = new Font("Arial", Font.BOLD, 30) įtDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) įlowLayout layout = new FlowLayout(FlowLayout.LEADING, 0, 0) Private static final Font font1 = new Font("Arial", Font.BOLD, 14) Here is an example of what I mean, with two panels top and bottom.

However, once those labels are wrapped in panels themselves it no longer works. I'm using this tAlignOnBaseline(true) and it properly aligns JLabels to the bottom of the panel. I have a case where I am adding JPanels to a FlowLayout, and they are not aligning themselves to the bottom of the layout.
