473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2331
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.