473,659 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JLabel's Problem

nanhiPari
8 New Member
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 2351
JosAH
11,448 Recognized Expert MVP
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
nanhiPari
8 New Member
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 Recognized Expert MVP
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
setBorderPainte d(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
5906
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 it would do so. Sample code is : JPanel logoPanel = new JPanel(); logoPanel.setLayout(new BoxLayout(logoPanel, BoxLayout.X_AXIS)); ImageIcon logo = new ImageIcon(_imageFileName);
1
8316
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 background is transparent, the color of the tabbed panel is there. The text is ok. (checkboxes and radiobuttons work ok.) It doesn't matter if the setBounds() is before or after the setBackground() Any advice appreciated.
0
2075
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(" Book Name =") Thanks
2
25550
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 i clicked... import java.awt.*; import java.awt.event.*; import javax.swing.*;
5
6848
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 frame.setVisible( true ); // display frame JLabel label = new JLabel("Text Label");
5
6914
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 id JLabel j2 = new JLabel("Name of DVD = " + dvd); //Displays dvd name JFrame frame = new JFrame( "Matt's DVD's" ); // Sets frame for label frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
1
2010
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 why. Any help would be greatly appreciated int playerCount = 0; private void addPlayerButtonActionPerformed(java.awt.event.ActionEvent evt) { String name = nameTextField.getText();...
6
6058
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 with border. i've set the border for the JLabel, but then it appears as a small rectangle, i've tried to use the setSize and the setMinimumSize but still it appears so small. how to make it be displayed with a fixed size even if it's empty (contains...
2
15977
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 everything displayed how I want it to be. Here are the snippets of my code that I think are the important parts. Let me know if there is anything else needed to help me. Thanks in advance. JLabel dice1 = new JLabel(); ImageIcon one = new...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8528
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.