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
2
votes
1 answer

Kivy \\ How to tie a button to the bottom of the boxlayout

from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.label import Label from kivy.core.window import Window from kivy.uix.scrollview import ScrollView from kivy.effects.scroll import ScrollEffect from kivy.uix.widget…
oleksandrigo
  • 152
  • 1
  • 7
2
votes
1 answer

GUI Box layout Y AXIS not inline

I am designing this GUI the overall frame is using a BorderLayout, then there are 3 panels, the boggle Board panel is using GridLayout, the Enter Words Found Panel (consisting of the JTextArea, Time left JLabel, and Shake Dice JButton) is using…
Graham Chapman
  • 383
  • 3
  • 14
2
votes
2 answers

BoxLayout doesn't respect glue when JLabel contains HTML

I have a component I've written that uses BoxLayout to layout some JLabels horizontally, followed by glue (I'd like the JLabels' width to remain fixed). For example: I need to add two lines of text to each JLabel, so I'm using a bit of HTML. As…
rainbowgoblin
  • 1,221
  • 12
  • 28
2
votes
1 answer

How can get components to stretch across an entire row using BoxLayout?

I'm looking at the How To Use BoxLayout documentation, which clearly says that What if none of the components has a maximum width? In this case, if all the components have identical X alignment, then all components are made as wide as their…
sbrattla
  • 5,274
  • 3
  • 39
  • 63
2
votes
2 answers

How to center JLabel in a panel with BoxLayout

I'm a newbie in Java programming and I got a question about BoxLayout. I can't get the JLabels centered in a panel with BoxLayout What I want is to change from what I got now: to this: getting the labels being totally in the middle of the…
lhy
  • 39
  • 1
  • 7
2
votes
1 answer

Java Swing why does aligning only work sometimes?

There are several different commands to explicitly align elements in Java Swing. It appears that these commands only work under some extremely specific constraints and these constraints are not documented anywhere. Most of the time that I want to…
Atte Juvonen
  • 4,922
  • 7
  • 46
  • 89
2
votes
2 answers

BoxLayout adding left margin

I've got a JPanel that has a BoxLayout (Page axis), and I want to lay out two components, one on top of the other. My problem is the margin to the left of the large lipsum box, how can I get rid of this? If I don't add the top components, there is…
Luke Moll
  • 428
  • 6
  • 18
2
votes
1 answer

Force space between Panels to be 0 using BoxLayout?

Currently as part of a project I'm working on, I am implementing a component which can be used to visualize a permutation of bits (as part of a cryptographic algorithm). I am doing so by creating two rows of "pins" and connecting them by drawing…
Mike Carpenter
  • 197
  • 1
  • 2
  • 9
2
votes
2 answers

Adding a JLabel to a JFrame that is using BoxLayout

I am creating a JFrame that contains a JPanel with a grid of buttons. Everything works fine but I then want to add a JLabel above the panel of buttons but the label never appears. It does appear if I don't use BoxLayout, though. Any help is…
0xCursor
  • 2,242
  • 4
  • 15
  • 33
2
votes
1 answer

Why does glue disappear when I wrap a Panel with another one?

Here's what I tried: JPanel p1 = new JPanel(); BoxLayout b1 = new BoxLayout(p1, BoxLayout.X_AXIS); p1.setLayout(b1); p1.add(new JButton("1")); p1.add(Box.createHorizontalGlue()); p1.add(new JButton("1")); And it works pretty fine. The buttons are…
user2953119
2
votes
3 answers

How can I stop a JTextArea and JTextField from stretching?

This has probably been answered here, but my searches drew up a blank, perhaps I am looking for the wrong thing. How can I stop a JTextArea and a JTextField from stretching? Does swing provide a panel spacer of some sort which I can add that will be…
Lieuwe
  • 1,734
  • 2
  • 27
  • 41
2
votes
3 answers

How to make a component full width in BoxLayout

I have a JPanel, that lists a set of Jlabels. I would like to make the width of each label wide as the panel's size. So it will be wide but but text stays in the left. I am using BoxLayout to list labels. Here is the code: public class…
Dan
  • 577
  • 1
  • 12
  • 38
2
votes
1 answer

BoxLayout left margin for TextField

I am using a BoxLayout and I have 2 JTextFields. I need to add some margin options to them because they are too close to the window border. Code: JPanel top = new JPanel(); top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS)); top.add(new…
Grigore Dodon
  • 137
  • 3
  • 13
2
votes
1 answer

JTextField stretches to fill BoxLayout.PAGE_AXIS

I have added a JTextField to a JPanel that is using BoxLayout.PAGE_AXIS. I am then adding this panel to a content pane at BorderLayout.CENTER. Right now my text field is stretching the entire width and height of BorderLayout.CENTER. Is there a way…
MasonAlt
  • 369
  • 2
  • 3
  • 12
2
votes
2 answers

Close Gps on BoxLayout

I have created a setup of buttons using Box. The problem is there are gaps between all the buttons. Below is an MCVE version of my code. What I want to achieve is that the buttons "ONE" and "TWO" are touching side by side, with no gap, and buttons…
user3932611