• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make component stick to the right?

 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is't Box good option?


Did you read the answers that have already been given???
 
Volodymyr Lysenko
Ranch Hand
Posts: 511
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic