Questions tagged [boxlayout]

BoxLayout is a Java Swing layout manager that allows multiple components to be laid out either vertically or horizontally.

BoxLayout is a layout manager that allows multiple components to be laid out either vertically or horizontally. The components will not wrap so, for example, a vertical arrangement of components will stay vertically arranged when the frame is resized.

enter image description here

Nesting multiple panels with different combinations of horizontal and vertical gives an effect similar to GridBagLayout, without the complexity. The diagram shows two panels arranged horizontally, each of which contains 3 components arranged vertically.

For examples and more details refer to How to Use BoxLayout tutorial.

347 questions
3
votes
1 answer

How to make BoxLayout behave as vertical FlowLayout?

FlowLayout performs "pressure" from the right, so as all components are trying to take their minimal widths. Contrary, BoxLayout tries to spread all components to fill entire height of the space. Can I add some filler as last component or something…
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
3
votes
1 answer

Unforeseen error when using java.swing.Box

Details I have some questions concerning the javax.swing.Box class (please see http://docs.oracle.com/javase/7/docs/api/javax/swing/Box.html for documentation). I have recently updated my dev environment to Java 7u5 and am in the process of…
Hegemon
  • 433
  • 7
  • 21
3
votes
3 answers

Aligning JLabels in BoxLayout

I've been searching around for days trying to find the answer to this, and I can't find out what's wrong. What I want to do is make it so the top JLabel (called display) align to the right and the bottom JLabel (called notice) to align to the left.…
charlieshades
  • 323
  • 1
  • 3
  • 16
3
votes
2 answers

How can I change the order of the BoxLayout in kivy?

I am testing kivy and I want to create a BoxLayout so to stack some buttons. My problem is that the children that are added to the layout follow a bottom-top logic while I want the opposite. Do you know how can I reverse the order? Thanks!
Socratesx
  • 71
  • 9
2
votes
2 answers

Is it possible to add components dynamically to the middle of BoxLayout

I'm building a small swing application where I've created contentpane with BoxLayout aligned to Y axis and added another 2 JPanels to it. So far so good. Now I've stumbled upon a problem where I have to re-create the first JPanel and add it to the…
Kristjan Toots
  • 81
  • 1
  • 1
  • 3
2
votes
3 answers

Horizontal placement of buttons in BoxLayout depending on OS

I am placing [OK] and [Cancel] buttons horizontally in a Box (which has BoxLayout). Later I add this Box to BorderLayout.PAGE_END in content pane of JDialog. This works perfect in Windows, so [OK] is to left of [Cancel] - just like I have…
txx28
  • 21
  • 2
2
votes
3 answers

GridBagLayout panel expands ignoring BoxLayout's vertical glue

In the example below I have a JPanel with BoxLayout which contains another JPanel with GridBagLayout. By adding a vertical glue I expect the contents of the inner panel to be "glued" to the top of the outer panel. But I see the label "A" in the…
ililit
  • 1,309
  • 1
  • 12
  • 19
2
votes
2 answers

How to prevent Boxlayout/Box from stretching children components?

As you can see in the runnable code below, i try to have a Box with expandable child-boxes. The children Boxes can change they size and this all works good. The main problem is that the size is always relative to the parent. But I want them to have…
Anthea
  • 3,741
  • 5
  • 40
  • 64
2
votes
2 answers

Boxlayout stretch my Jpanels

Hey (: This is my first time asking help on this forum so I hope I have done everything correctly Okay my problem is what I have marked with red. My JPanel uses a Boxlayout with BoxLayout.Y_AXIS orientation. I guess that is not the right choise. I…
Sune Lindhard
  • 23
  • 1
  • 3
2
votes
0 answers

How can I change the height of Boxlayout Dynamically?

I am trying to change Boxlayout height dynamically. There will an empty Boxlayout at the beginning, then with a ToggleButton I will add Buttons on that Boxlayout vertically. But this Boxlayout locates in Gridlayout which has ScrollView. And the…
2
votes
1 answer

Why does my box Layout change size even after setting Sizes of JPanels

I have been trying to adjust my JPanel sizes while using LayoutManager such as BoxLayout to arrange components inside that Layout in a specific order, I achieved the way I want it to look by NOT USING the Box Layout Manager. Original idea which I…
Aravind K
  • 25
  • 5
2
votes
1 answer

Java Swing BoxLayout layout of outer panel changes when I specify layout of inner panel

I'm very new to Java Swing. I'm using y-axis BoxLayout on an "outer" panel that contains 2 inner panels. Here you can see with this basic code, the 2 inner panels get an equal share of the height avaiable in the box layout (first inner panel yellow,…
Geoff L
  • 765
  • 5
  • 22
2
votes
2 answers

Components not shifting when removing from BoxLayout

I'm using a BoxLayout and removing components from it dynamically, something like this: public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final JFrame…
Michael Berry
  • 70,193
  • 21
  • 157
  • 216
2
votes
1 answer

AlignmentX and Y of a JComponent without a BoxLayout

I've seen some people using the setAlignmentX() and setAlignmentY() methods without a BoxLayout (e.g. when using a BorderLayout and other kinds of layouts). Is this correct or does it do something at all? I haven't found any documentation explaining…
hexstorm
  • 318
  • 4
  • 14
2
votes
1 answer

Java: Issue with jsplitpane and boxlayout

I want to get rid of the empty space to the left of the jsplitpanes: Here's my code: getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); JSplitPane splitPane = new…
opike
  • 7,053
  • 14
  • 68
  • 95