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
0
votes
0 answers

Can't Make a Box Layout work

New to Java Swing layouts. After much reading, I think that the best layout for me is the box layout. My JDialogBox has a JTabbedPane on it. On the JTabbedPane, there are four JPanels. I am focusing on laying out one of these panels, called…
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
0
votes
1 answer

BoxLayout sticking to top

I just started messing around with the BoxLayout manager. I've made two buttons next to each other, and the third one should go to the next line (underneath the first two), and the two first buttons should be at the top of the frame. How can I…
Patrick Reck
  • 11,246
  • 11
  • 53
  • 86
0
votes
4 answers

Dynamically growing JPanel with BoxLayout (on a null layout)

I have a JPanel with a vertical BoxLayout on top of a JPanel with a null layout. I would like the JPanel with the BoxLayout to grow as the components are being added. See this code: public static void main (String[] args) { JFrame f = new…
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
0
votes
1 answer

BoxLayout not adding another JPanel

I am trying to add a second JPanel to my window, which uses BoxLayout. For some reason everything beyond my overridden JPanel refuses to appear. Here's the code: public void initialize() { JFrame.setDefaultLookAndFeelDecorated(true); …
Thrfoot
  • 125
  • 2
  • 7
0
votes
1 answer

How to improve GUI by changing BoxLayout into a different LayoutManager?

I've a big problem with Swing in Java, I used BoxLayout for this but still it looks bad. Any suggestions about my usage of layouts, or how to change it to look like in assumptions? (here are assumptions) Container main = new Container(); …
USER_
  • 63
  • 4
0
votes
1 answer

Components in a BoxLayout move when some of the components resize

public class LabelResizing2 { public static JPanel createSliderPanel( int min, int max, int curr) { /*outer panel*/ final JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel,…
dwjohnston
  • 11,163
  • 32
  • 99
  • 194
0
votes
2 answers

how to add component in box layout on north of other and make them all anchor on south?

I try to make a very mini game. I have one JPanel, it uses a BoxLayout.Y_AXIS that contains three JLabel (name of JLabels = 1,2,3) I need a component inside that panel to anchor on South (so I use glue) The view result will be like…
mopr mopr
  • 193
  • 2
  • 4
  • 13
0
votes
2 answers

center a panel in a box layout row in java

I have this code below to create a page inside of a tab. I want each layout in one row of the overall box layout but i want the elements to stay in their original size and not expand to fill the width of the overall window. does anyone know what…
Kevin Foley
  • 119
  • 1
  • 8
0
votes
1 answer

using a box layout in java

the following codes created a box layout conviniently but the problem i have is the textfields occupy the entire rows. which is supposed to asume the parameter length in which it was specified. public void makeControlpanel(){ JPanel…
Abiodun
  • 959
  • 6
  • 17
  • 38
0
votes
1 answer

Disappearing JPanel

I have this JPanel (a) with BoxLayout. When I add another JPanel (b) to it, with setPreferredSize() and setBackground(), it gets drawn nicely on (a). However, if I setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS) on (b), it doesn't get drawn at…
Karlovsky120
  • 6,212
  • 8
  • 41
  • 94
-1
votes
0 answers

python SyntaxError: invalid syntax when using function from .kv file

I'm using a library on python called kivy. I have the main code file "ngen.py" and the other file used for ui "ngen.kv". When I use boxlayout in ngen.py I get an error message even though they are in the same dir. [Running] python -u…
rinobu45
  • 1
  • 2
-1
votes
1 answer

Swing Layout with CardLayout

How can I have get the layout in picture ? Current issue I am facing is that I am able see the dropdown 1 and text box but I do not see the dropdown 2 and text box aligned to it displayed. private final JComboBox firstComboBox; private final…
Tanu
  • 1,286
  • 4
  • 16
  • 35
-1
votes
1 answer

How to make a spoiler in Swing (and why a simple solution is not working)

I'm trying to make a spoiler effect in Swing (like /
tag in HTML). However, if I toggle setVisible() method, the height of my parent containers is not calculated correctly. All my parent containers of the panels that I'm trying to…
Alex654
  • 1
  • 6
-1
votes
1 answer

Java BoxLayout place some Objects left and some right

i want to place child components to a JPanel. But the problem is, that i want to place the components on the left-hand side and on the right-hand side of the parent JPanel. I'am using a BoxLayout and currently i have set the X Alignment of the child…
Chippi_5
  • 1
  • 4
-1
votes
1 answer

Swing: can't center a vbox inside a JPanel

I have this code that creates a simply JPanel with text User profile panel username: a user email: email@gmail.com Button1 Button2 Each row - is a HorizontalBox and all rows come into a VerticalBox. I try to center the result VerticalBox, but it…
parsecer
  • 4,758
  • 13
  • 71
  • 140