472,805 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

JLabel's Problem

nanhiPari
hello everyone

i need to create DYNAMIC JLABElS(say 5)..yes i know it sounds easy

but i also have to give them Events n then want to refer each of them when ever Mouse is Clicked on a Specific Label with its Label Name or Text..

i tried it by...



Expand|Select|Wrap|Line Numbers
  1. Object lbl_name
  2.  
  3. for(n1=1;n1<=5;n1++)
  4.  {
  5.  
  6.         lbl_name = new String("lbl_cal");
  7.  
  8.  
  9.          lbl_name = new JLabel();
  10.  
  11.          ((JLabel)lbl_name).setName(lbl_name.toString());
  12.  
  13.           panel1.add((JLabel) lbl_name, new org.netbeans.lib.awtextra.AbsoluteConstraints(x, y, 40, 20));
  14.  
  15.  
  16.            ((JLabel)lbl_name).addMouseListener(this);
  17.  
  18.             ((JLabel)lbl_name).setText(n1);
  19.  
  20. x = x+10;
  21. y = y+2;
  22. }
  23.  
  24.  
  25.  



n then calling it in MouseClicked event..



Expand|Select|Wrap|Line Numbers
  1. public void mouseClicked(MouseEvent me)
  2.   {
  3.  
  4.     System.out.println("CLICKED on Label..." + ((JLabel)lbl_name).getText());
  5.  
  6.   }
but this is not giving me the REsult..as this alwayz prints 5 (i.e LAST JLABELS setText..


PLZ help!!!need Urgently..

thankz is Advance

Cheerz!!
Sep 7 '07 #1
3 2298
JosAH
11,448 Expert 8TB
hello everyone

i need to create DYNAMIC JLABElS(say 5)..yes i know it sounds easy

but i also have to give them Events n then want to refer each of them when ever Mouse is Clicked on a Specific Label with its Label Name or Text..
Users prefer to click on JButtons; not on JLabels. You could do it but it'll confuse
your users.

kind regards,

Jos
Sep 7 '07 #2
Users prefer to click on JButtons; not on JLabels. You could do it but it'll confuse
your users.

kind regards,

Jos
well yesh JOs i know that user click on the JButtons. but according to the thing i need to do is requiring to click on the JLabels


thankz for ur Reply

any ANswerz to my Problem ??

cheerz!!
thankz in advance
Sep 9 '07 #3
JosAH
11,448 Expert 8TB
well yesh JOs i know that user click on the JButtons. but according to the thing i need to do is requiring to click on the JLabels
You're definitely on the wrong track then because a JLabel doesn't respond to
events and using low level MouseEvents for that will be a total mess because
you have to poop up that JLabel to an 'almost' button.

Better remove the JButton border so it'll look like a JLabel. See the
setBorderPainted(boolean painted) method.

kind regards,

Jos
Sep 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: prabhat | last post by:
Hi, I am getting this weird behavior. I have couple of gif and jpg files that I would like to display in JLabel. It displays one jpg image but it does not display other gifs and jpgs. Any idea why...
1
by: Phil... | last post by:
I have the following code to put a label on a tabbed panel. It does not set the background though. If I put in a "slabel.getBackground()" it returns the color I chose for the set. It is like the...
0
by: Mike | last post by:
Hello, Is there a way of setting text for a JLabel after a certain amount of empty characters. For example, I want to avoid doing this JLabel label = new JLabel(); label.setText(" ...
2
by: reon | last post by:
Hi in this code when i clicked login button...it shows output as login... But when i clicked each time its repeating .. i want to see that only ones ... I want to clear the previous login before...
5
Shinzon
by: Shinzon | last post by:
ok so far I have got: JFrame frame = new JFrame( "Matt's DVD's" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setSize( 420, 170 ); // set frame size ...
5
Shinzon
by: Shinzon | last post by:
Ok so I have been working on this for a moment now and wondering how to add multiple jlabels to a jframe. the code looks like this: JLabel jl = new JLabel("DVD ID #= " + dvd); //Displays DVD...
1
by: tommyny04 | last post by:
I have a method addPlayer that's supposed to add a JLabel to a JPanel and update the JPanel. The JLabel is just a label with a player's name in it. The code I've wrote doesn't work and I'm not sure...
6
by: thesti | last post by:
hi, i have a JLabel inside a JPanel of which layout manager is BoxLayout. i will display an image with the JLabel at runtime, when the application first start, it will appear as an empty box...
2
by: Coreyja | last post by:
Im trying to display a png image by setting it as a ImageIcon and then putting that in a JLabel. I cant get it to display the image. I am using a null layout as it is the simplest way for me to get...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.