Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add components from the top of the JPanel using GridBagLayout?

 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ALl,

How to add components from the top of the JPanel using GridBagLayout?

I hope by default it starts from the centre.

Here is my code.


JPanel panel = new JPanel();
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
panel.setLayout(gbl);
priceButton = new JButton();
panel.add(priceButton);

I tried diff options but it didnt work.

Thanks in advance.

Regards,
Kannan Somaiah
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain your question further? Do you want to add your components
in North side or do you want to pile up your components one by one ?
 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add my components in the North side.

Thanks,
Kannan Somaiah
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.

Did you try the above in your code?
 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your erply. I am adding components to a JPanel. I don't have frame here. Is there any similar method which can be applied to JPanel and get the same things done on a JPanel?

Thanks,
Kannan Somaiah
 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the code snippet you had sent. But I couldn't crack it.

Regards,
Kannan Somaiah
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code



why do you use GridBagLayout? Use borderlayout

 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I started with gridBagLayout as I have to add many more components to the same panel.

So can I solve this problem using GridBagLayout itself?

Please advice.

Regards,
Kannan Somaiah
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would get better solution if you give us the clear requirement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic