Current position:  Home > Default > Boxlayout - align things to the right?

Boxlayout - align things to the right?

Time:November 30
Advertisement
Hi all,
I have a Box setup with PAGE_AXIS layout.. The Box will contain several JLabel icons (no text) and will be wider than the icons combines. I want the extra space to appear on the left side instead of the right. How do I add this?
I've tried adding Box.createHorizontaGlue() as the first thing but that doesnt help.
FYI, this container will implement TableCellRenderer
So like this:
[ .........................[  ] [  ][  ][  ][  ][  ][  ]|
-------------------------------------------
Advertisement
As already mentioned in a boxLayout you have to set the alignment of each child to get the overall alignment. While that's acceptable in a small container, it can get boring in a bigger environment. So in the long run you might consider switching to more powerful LayoutManager like JGoodies FormLayout (http://forms.dev.java.net/): it lets you define component alignment on a per-column/row basis.
Personally I switched completely to FormLayout (from nested BoxLayouts which are not too bad, IMO) and developed a visual builder for it (http://swingempire.de/palace/FormBuilder) <g>
Greetings
Jeanette

BoxLayout alignment issue

-0001-11-30

Hello, Can someone please explain why my JPanel with a BoxLayout will not align the components to the left? Can I not use the BoxLayout with a JPanel? If not, is there another LayoutManager I can use that will display the component aligned to the lef

BoxLayout alignment

-0001-11-30

Hello, the following code shows four "column" panels, each having a BoxLayout.Y_AXIS and a header label inside. In the tutorial I read: "In general, all the components controlled by a top-to-bottom BoxLayout object should have the same X al

More BoxLayout alignment issues

-0001-11-30

Hi everybody, I'm trying to create a bar graph with BoxLayout, but I'm having a problem. The BoxLayout always orients the buttons in a line on the exact center of the panel, which can result in a lot of extra space. I'd like to have the line be off-c

Aligning swing components

-0001-11-30

hello everybody, i read about FlowLayout,BorderLayout,GridLayout,BoxLayout,CardLayout and GridBagLayout,but i still have a problem in aligning the components. I want to desgin a Wizard Frame like in this Following Website: http://java.sun.com/product

Align left panels inside BoxLayOut / Center a frame center screen

2015-10-11

Hi, I've googled for a good while now so now I'm posting the question I have not found a satisfactory answer. It may be that I've been searching by the wrong terms, because it's an easy thing in concept. This is a JSwing question and all terms below

Alignment Problem - BoxLayout

-0001-11-30

import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class Test extends JFrame {      public Test

Add a JLabel below a JTextArea in a boxlayout

2015-10-11

I have a JTextArea in a JScrollPane in a GUI, and I'm using BoxLayout. Occasionally, I wish to add a JLabel to my JScrollPane, which works fine. However, since my BoxLayout is set to the Y_Axis layout, the JLabel always ends up being centered below t

Center JComboBox in BoxLayout

2015-10-11

I try to center a single JComboBox in a JPanel with BoxLayout. But it is still left aligned. I use: jpanel.setLayout(new BoxLayout(jpanel,BoxLayout.X_AXIS)); ...add(jpanel); jcombo.setAlignmentX(0.5F); jpanel.add(jcombo); What is missing?wow, it work

Boxlayout question

-0001-11-30

hey all i have a jfame that have a panel that have a y-axis boxlayout, in this panel i have another panel that have an x-axis boxlayout, in this panel i added a jlabel and a jtextfield but the problem is that those two components appear in the center

JCombobox text alignment multiple?

-0001-11-30

Hi all, i have a JComboBox that i dynamically update when the user adds a new item to a JTree The JCombobox displays the parent name + the number of children of that node: Node1(4) Node2(5) Node3(2) Node4(0) but because the Node name has a variable l

Alignment problem in Panel

-0001-11-30

I am not able to align all components of the respective panels to the center when I add the composite panel to center of a BorderLayout frame. Pl suggest improvements in code below: public class CenterPanel extends JPanel { BoxLayout oBoxLayoutCenter

BoxLayout : unslightly gaps betw vertical components?

-0001-11-30

Hi, all. I've this BoxLayout with PAGE_AXIS alignment, it works, but there is this big gap between the components vertically. The components are self-defined and consists a pair of JLabel and JTextArea. How do I pack the components tighter vertically

BoxLayout: components with different alignmentX

-0001-11-30

Hi all. Java newbie here.. Here's what I'm trying to do: Use BoxLayout to "left-align" three components, and have one component at the bottom centered at its container/frame. Something like this: | ( One )        | | ( Two )        | | ( Three )

BoxLayout: problems

-0001-11-30

I've a frame this default BorderLayout. Then I create this Panel: JPanel rightPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));and insert it into east of the frame: frame.add(rightPanel, BorderLayout.EAST);Then I create a BoxLayout like this: JPan

BoxLayout allignment

-0001-11-30

I would like the JLabel "addedSectionLabel" to be left aligned however it is always center alligned, any ideas on how to achive this? JPanel topLeftPanel = new JPanel(); topLeftPanel.setLayout(new BoxLayout(topLeftPanel, BoxLayout.PAGE_AXIS)); J

Component Alignment issues.

-0001-11-30

Hello, I am having a very difficult time aligning my components along the y Axis. I have a JFrame with a BorderLayout. A JTabbedPane in the center of the Frame with a BoxLayout.PAGE_AXIS. Then I have a JScrollPane in a tab. Then a JPanel is added to

Need LayoutManager that resizes and supports right-aligned children

-0001-11-30

I have two labels that I want to appear inside JPanels such that they have minimum 2 pixels padding between the text and the border of the JPanel, and the leftmost label is right justified, while the rightmost label is left justified. For example) [+

Setting a JPanel alignment

-0001-11-30

hi all, I'm using a BorderLayout for my simply application. I have created a JPanel that contains two buttons, as follows: JPanel pannello_pulsanti=new JPanel(); pannello_pulsanti.setLayout(new BoxLayout(pannello_pulsanti, BoxLayout.LINE_AXIS)); salv

Can't get Landscape printing aligned correctly...

-0001-11-30

I'm new to Java and this forum, so any help with the following would be greatly appreciated: Description: Incorrect height alignment when printing Landscape. Hardware: Power Macintosh 8500/120, 48MB RAM. Brother HL-1650 Laser Printer, 8MB RAM. Softwa