• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JLabel.setbounds method not working.

 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try the code below and it displays the jlabel below the click.
Code:

Any help apprieiated!
Thanks!
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.
Do not use setBounds. You will run into all kinds of problems (one of which you are already experiencing)
The proper way to build your UI is using layout managers. More on that here http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it displays the jlabel below the click


There are two reasons for this:

1. You added the listener to the frame so the coordinates a relative to the frame, which included the title bar. The component is added to the content pane of the frame so the coordinates are different. Add the listener to the content pane:



2. For a component the location is the top/left and the component is painted below that point. To paint above the point you need to adjust the "Y" value:


 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about this message
 
Heg Lachher
Greenhorn
Posts: 28
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:The proper way to build your UI is using layout managers.

The first problem i ran into was using the layout manager. It placed the JLabel on the west side of the page so I set it to null. That's why i'm not using a layout manager.
Layout Manager.
Even though they're meant to help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic