aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to make component stick to the right? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make component stick to the right?" Watch "How to make component stick to the right?" New topic
Author

How to make component stick to the right?

Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

I have simple JDialog with BorderLayout.
I add Box with BorderLayout.SOUTH.
But Box is positioned on the left of south area.

How to position component to the right of south area?
Aso I want it to stay on the right even if JDialog is resized.

Thank you!


True person is moral, false is right!
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 156
I add Box with BorderLayout.SOUTH.

Box is paramater from BoxLayout ---> change alingment for BoxLayout

Box is something like as (J)Component ---> put there JPanel with FlowLayout.RIGHT

Box is something else, very different ---> for better help sooner post an SSCCE, short, runnable, compilable demonstrated a.m. issue
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Thank you very much for reply!

My code is :

As you can see I add Box okCancelButtonsBox to JDialog below JTabbedPane tabbedPane
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
1. You did NOT post a SSCCE. The code you posted does not help us. The problem is the layout manager that you use in your Box class.

2. You were given a solution in your previous answer. Use a FlowLayout with right alignment.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Volodymyr Levytskyi wrote:Hello!

I have simple JDialog with BorderLayout.
I add Box with BorderLayout.SOUTH.
But Box is positioned on the left of south area.

No, it isn't. the Box will fill the SOUTH area. The Components held by the Box may well be positioned to the left; that's the way BoxLayout works.

While you can probably align the components to the right in two different ways with Box, my advice is to choose a more appropriate layout. Unless of course this is homework and you have to use Box.

Here's a learning resource: Laying Out Components Within a Container.


luck, db
There are no new questions, but there may be new answers.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Thanks for replies!

I am using Box with default layout LINE_AXIS(from left to right)

I do not know how to tell Box to position components from right to left.

I cannot set a layout by box.setLayout(...) because it gives exception.

I want to wrap only two buttons on south of JDialog.
I want to use for this smth simple and efficient(meanning do not slow down appearing of JDialog).
Is't Box good option?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
Is't Box good option?


Did you read the answers that have already been given???
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Thanks!

I did as was suggested. I set this on JDialog :

Now my dialog is just as I wanted.

I don't know maybe Box is not efficient to use...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make component stick to the right?