• Post Reply Bookmark Topic Watch Topic
  • New Topic

Text, buttons & TextFields stuck at top?

 
Ryan Taubert
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a launcher for my client & I'm running into an error... My buttons or anything I try to set bounds to is stuck at the top of my JPanel?

Example:


and my code:
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use setBounds() to set the size and location of components.

Swing was designed to be used with layout managers. The default layout manager for a JPanel is the FlowLayout, that is why the components are displayed on a single line.

If this is not the layout you desire, then use a different layout manager and don't forget you can nest panels of components that use different layouts to achieve your desired effect.

Read the section from the Swing tutorial on Layout Managers for more information and examples.

Also, when you post code in the forums don't forget to use the "code tags". You have to select the text before you click the code button.
 
Ryan Taubert
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Don't use setBounds() to set the size and location of components.

Swing was designed to be used with layout managers. The default layout manager for a JPanel is the FlowLayout, that is why the components are displayed on a single line.

If this is not the layout you desire, then use a different layout manager and don't forget you can nest panels of components that use different layouts to achieve your desired effect.

Read the section from the Swing tutorial on Layout Managers for more information and examples.

Also, when you post code in the forums don't forget to use the "code tags". You have to select the text before you click the code button.


I did use code tags... just accidentally put the code on the outside. Anyways Even with layout managers it still didn't work. I'f I build another jpanel with similar setup but no background the buttons move?
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did use code tags... just accidentally put the code on the outside.


So you edit the question to fix the problem. Don't ask us to read unformatted code.

Anyways Even with layout managers it still didn't work.


You did something wrong and I'm not a mind reader, I can't guess what you might have done.
 
Ryan Taubert
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
I did use code tags... just accidentally put the code on the outside.


So you edit the question to fix the problem. Don't ask us to read unformatted code.

Anyways Even with layout managers it still didn't work.


You did something wrong and I'm not a mind reader, I can't guess what you might have done.


You don't need to read my mind... You read the code I posted above & hint me to where I messed up on my code.
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already told what was wrong and hinted at how to fix it. I even gave you a link to a tutorial to read.

I can't offer specific advice because all you have stated is that it is wrong. You haven't stated what is should look like.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!