wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JLabel.setbounds method not working. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JLabel.setbounds method not working." Watch "JLabel.setbounds method not working." New topic
Author

JLabel.setbounds method not working.

Heg Lachher
Greenhorn

Joined: Aug 12, 2013
Posts: 28

I try the code below and it displays the jlabel below the click.
Code:

Any help apprieiated!
Thanks!


Remember to look at this before posting.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10170
    
    8

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
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

Joined: Aug 12, 2013
Posts: 28

Sorry about this message
Heg Lachher
Greenhorn

Joined: Aug 12, 2013
Posts: 28

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.
 
wood burning stoves
 
subject: JLabel.setbounds method not working.
 
Similar Threads
java swing repaint
Reduce CPU usage for a thread
how to paint some shape over another JComponent
Draw a point on an image in java
JLabels are not visible