473,434 Members | 1,674 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,434 software developers and data experts.

Override JTree listener?

37
Hello everyone!
I'm stuck with a problem, caused by a mix of listeners in a JTree.

Here goes:
I created my own renderer for the tree, that is one JLabel (icon+name), and then another JLabel (let's name it button) that has a small icon. I want the user to be able to click on the "button" JLabel and something to happen.

e.g.
Program1 (on)
Program2 (on)

assuming (on) is an icon. When the user presses (on) i want the icon to turn into (off) and turn off Program1.
as shown in this image:



Here is the code:
Expand|Select|Wrap|Line Numbers
  1.  public TreeRenderer()  {
  2.     renderer = new JPanel(new GridLayout(0, 1));
  3.     renderer.setLayout(new BoxLayout(renderer, BoxLayout.X_AXIS));
  4.     titleLabel = new JLabel(" ");
  5.     titleLabel.setForeground(Color.black);
  6.     renderer.add(titleLabel);
  7.     buttonLabel = new JLabel(" ");
  8.     buttonLabel.addMouseListener(new java.awt.event.MouseAdapter() {
  9.             private boolean on;
  10.  
  11.             @Override
  12.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  13.                 System.out.println("shalal");
  14.                                 System.out.println(" clicked ");
  15.                 on=true;
  16.                 icon = createImageIcon("http://bytes.com/images/jtree red.jpg","");
  17.                 buttonLabel.setIcon(icon);
  18.             }
  19.             @Override
  20.             public void mouseEntered(java.awt.event.MouseEvent evt) {
  21.                 System.out.println("sda");
  22.             }
  23.             @Override
  24.             public void mouseExited(java.awt.event.MouseEvent evt) {
  25.                 System.out.println("14");
  26.             }
  27.         });
  28.  
  29.     renderer.add(buttonLabel);
However, when I click on the "button" nothing happens. Does anyone have any idea?
Thanks in advance!
Alex
Mar 12 '11 #1
0 1665

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

Similar topics

2
by: Mitch Williams | last post by:
I've been working with a JTree based on a custom TreeModel. Unfortunatly, I cant figure out how to force it to update the entire tree-- there simply dosnt seem to be a way to say "OK, your data...
1
by: Bernard Koninckx | last post by:
Hello everybody, I'vee a small problem with a JTree. I make an expand from a node. And after this operation the selection is lost. How can I do reselect the node than I come expand ? Thanks...
2
by: Piet | last post by:
Hi there, I have managed to write a small java program that display an xml file in a JTree. This was achieved by defining a suitable tree model. THe program works...somehow. The nodes (elements...
0
by: Lucia | last post by:
hello, I habe a Java Program that displays the XML document in a Java JTree using DOM. Now I can add, delete and edit the JTree Elements. But I don't know how to show the attributes also in the...
2
by: Roger | last post by:
I have an application that I want to run in the background until F7 key is pressed. Does anyone know how to implement a listener for F7 keypress to activate application?
0
by: luvping04 | last post by:
Hey, i told to make a java program to load xml into JTREE using SAX api. i'm suppose to load the 1st layer of the jtree and hide the subtree into memory. How can i load the subtree into...
0
by: flavourofbru | last post by:
Hi, I am converting a given html document into a tree structure and displaying it using JTree and DefaultMutable classes. By using the html parser and the JTree functionality, I can display the...
1
by: flavourofbru | last post by:
Hi, I am presently trying to display an XML document as a tree structure. I am able to do it using JTree and SAX Parser. Now I would like to get the parents of all non-leaf nodes and display...
2
by: ace84 | last post by:
Hi, I am creating an application where I want to show a file system. I have never worked with them before, so i am not sure on what I need to do to accomplish my goal. So far I found a script through...
1
by: sivakrish85 | last post by:
Hi, this is krishna i am on developing FTP in java.Here i display the server Files and client Files in tree view using JTree.So my question is that once the client send the file to...
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
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,...
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...
1
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...
0
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,...
0
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.