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

Java/Swing Box Layout with Separator

Here is the code: Box twoPanelBox= new Box(BoxLayout.Y_AXIS); twoPanelBox.add(panelA); // red twoPanelBox.add(new JSeparator(SwingConstants.HORIZONTAL) ); twoPanelBox.add(panelB); // black And here is what i get: The red and the black panel are…
MemLeak
  • 4,456
  • 4
  • 45
  • 84
5
votes
3 answers

What is the difference between x_axis and line_axis of boxlayout in java?

Both x_axis and line_axis arranges components from left to right. Then what's the difference between them? This question is from Java Swing boxlayout layout manager.
5
votes
2 answers

Keep BoxLayout From Expanding Children

I want to stack some JComponents vertically inside a JPanel so they stack at the top and any extra space is at the bottom. I'm using a BoxLayout. The components will each contain a JTextArea that should allow the text to wrap if necessary. So,…
user1052335
5
votes
1 answer

Layout manager in C#

I am trying to design a UI in C# . I come from Java background and am familiar with the different layout managers in Java. So what I am trying to do is: I have a Pane. To this pane I wish to add controls one below the other. In Java I would have…
Nikhil
  • 1,279
  • 2
  • 23
  • 43
4
votes
2 answers

How to I change the size of an element in a BoxLayout?

I have this class: package com.erikbalen.game.rpg; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class Gui extends JFrame implements ActionListener { /** * */ private…
Erik Balen
  • 275
  • 1
  • 4
  • 11
4
votes
1 answer

How to stretch QBoxLayout in PyQT5?

how to stretch the QHboxLayout and QVBoxLayout in PyQT5? Which method should I use? The pictures of result are given in links (as you see when window is small it also doesn't fit in the shape of the window) from PyQt5.QtWidgets import QApplication,…
Дарья
  • 147
  • 1
  • 12
4
votes
1 answer

How do I put a scrollPane on a BoxLayout?

I would like to have my JFrame that has a BoxLayout be able to have a scroll pane so I could just keep adding in Groups like if it was a receipt or invoice printer. Is there a way to add a ScrollPane? Question: How to add a ScrollPane to the…
Doug Hauf
  • 3,025
  • 8
  • 46
  • 70
4
votes
1 answer

Centering TextInput within a BoxLayout in Kivy

Here is a screenshot of my kivy app. I am trying to get the TextInput in the bottom left to be centered in the BoxLayout which it is in, and I don't want it to be the same size as the layout, I want it to be much smaller. This BoxLayout in question…
Totem
  • 7,189
  • 5
  • 39
  • 66
4
votes
2 answers

BoxLayout ignores setYAlighment

Here is a function: /** * Creates an instance of a JLabel with the given arguments * @param text The text to be displayed on the Label * @param font The font of the label * @param bold set to true if you want the label's text to be bold *…
Shaun Wild
  • 1,237
  • 3
  • 17
  • 34
4
votes
2 answers

How would I be able to achieve this expandable layout in Java? Flexible BoxLayout etc

I would like to be able to have three JPanels p1 p2 and p3, and have them lay out like so: I have been playing around with FlowLayout, BoxLayout etc but I'm not really sure if I am heading in the right direction. I am quite new with Java so I don't…
Adam K Dean
  • 7,387
  • 10
  • 47
  • 68
4
votes
3 answers

BoxLayout misunderstanding strut

I'm prgramming a simple input diagram in Swing. I use boxLayout to create a simple GUI of user input. Problem is that creating a horizontal strut between the JPanel of all the labels and the JPanel of the JTextFields causes the whole panel to shift…
hasdrubal
  • 1,024
  • 14
  • 30
4
votes
1 answer

Width in box layout

here is piece of my code: pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); JPanel a = new JPanel(); a.setAlignmentX(Component.CENTER_ALIGNMENT); a.setPreferredSize(new Dimension(100,…
hudi
  • 15,555
  • 47
  • 142
  • 246
3
votes
1 answer

Resizing of multiple JPanels to fit window

I'm pretty new to the Java Swing toolkit and have created a series of JPanel with JLabel components corresponding to each panel's index and value. However I can’t seem to make the panels correctly resize, when the window is too small to resize all…
3
votes
0 answers

BoxLayout artifact at 125% display scaling

This simple Java swing BoxLayout UI apparently results in certain pixels not being drawn (resulting in artifacts/garbage) when my display scaling is set to 125% (Windows 10): import javax.swing.*; public class Test { public static void…
tehtmi
  • 676
  • 4
  • 7
3
votes
1 answer

How do to put elements of different sizes immediately on top of one another?

The following program segment generates the output within the red box as shown in the figure: st = c.con.createStatement(); rs = st.executeQuery("SELECT itemName, itemMaxQty, itemImage FROM item"); while(rs.next()){ JPanel itemPanel = new…
Satellite Sage
  • 440
  • 1
  • 4
  • 13
1
2
3
23 24