JTree Renderer/Editor

I have a custom renderer for my JTree that uses a JPanel with multiple fields within it. I am using the same JPanel for editing as well within a custom editor that extends the DefaultCellEditor. When I select to edit, it edits okay. When I focus away (click elsewhere), the cancelCellEditing() method gets called. The display then shows the original values (before editing). If I select the cell for editing again, it shows the previously "edited" values.
It looks like the editor values are not getting transferred back to the renderer. Any ideas?
Gil

Does it work when you press ENTER before clicking out of the text field?

Similar Messages

  • Changing the event that starts JTree cell editor

    I've implemented a JTree that uses a custom cell renderer and editor. Everything is going well except for a look and feel issue. When I double click on a JTree entry or single click on a node that has already been selected, the cell editor starts immediately. This is way to generous, and I'm finding I'm often editing cells when I just want to navigate the tree.
    I'd much prefer to have the edit event be something harder to do like a right click or a triple left click. Is there a way to change the event that starts the JTree cell editor?

    DefaultCellEditor provides a method boolean isCellEditable(EventObject anEvent), by default it always returns true. Override that method in your cell editor to only return true if the event is a right click, or whatever you want.

  • Setting a JTree renderer breaks the focus traversal order

    Hello,
    I am not sure what's wrong, but when I set a customize JTree renderer it breaks the focus traversal order of my UI. Can someone tell me what's wrong and also how to prevent it from changing the order of my components?
    For instance, if I have component order 1, 2, 3, 4, 5 to begin with and after I call JTree.setCellRenderer(new SomeRenderer()), the order would change to something like this 1, 2, 4, 5, 3
    To give you an overview of what I am creating, I am customizing a UI that will be plug into JFileChooser to replace the default UI. I know I can create my own FocusTraversalPolicy, but the thing is that I don't know some of my components ahead of time. As long as I can prevent the order change, I think it would be fixed.
    Regards,
    Soot

    Try creating a Short, Self-Contained, Compileable, Executable
    program which has this problem. Right now it would take a
    mind-reader to solve your problem.

  • JTree rendering bug

    A bug exists with JTree rendering where a huge treenode is rendered for no apparent reason. It happens infrequently, but I've noticed that it's happening more frequently since I started using jdk1.4.2.
    This seems to be the only place I can find mention of it : http://forum.java.sun.com/thread.jsp?forum=57&thread=217494
    One of the solutions mentioned was to setRowHeight() on the tree. I don't like it, but it seems to be the only way around the bug at present.
    Does anyone know of any potential problems which might arise from explicitly setting the row height on a JTree?

    I basically need to be able to edit the rendered JTable as normal.

  • JTree rendering extra node and leaf icons at the end of the label

    Hi,
    Does anyone know how to add an icon to a JTree node or leaf in such a way that it will be displayed behind the text label?
    In an example:
    - rootnode
    - childnode [icon]
    |- leaf
    + childnode [icon]
    Where -/+ are the default (un)collapse icons
    I'd like to apply this to show additional information by using icons with respect to a node.
    I couldn't find anything on the net besides changing the default open/close node icons, yet that's not what I'm aiming for here.

    use this one.I think it will help u.Gd lk
    tree =new JTree(root);
    DefaultTreeCellRenderer renderer =(DefaultTreeCellRenderer)tree.getCellRenderer();
    renderer.setLeafIcon(new ImageIcon(getClass().getResource("leafimages/3.gif")));
    renderer.setClosedIcon(new ImageIcon(getClass().getResource("leafimages/1.gif")));
    renderer.setOpenIcon(new ImageIcon(getClass().getResource("leafimages/2.gif")));
    renderer.setBackgroundNonSelectionColor(new Color(15,85,134));
    renderer.setBackgroundSelectionColor(Color.YELLOW);
    renderer.setTextNonSelectionColor(new Color(217,227,227));
    renderer.setTextSelectionColor(Color.RED);
    renderer.setHorizontalTextPosition(SwingConstants.LEADING);
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    tree.setFont(new Font("Tahoma",1,12));
    tree.setBackground(new Color(15,85,134));

  • JTree rendering failure : big empy space displayed

    Hello,
    I have a problem using a JTree with jdk 1.5 update 10. I could not find anything in the bug database that seemed to link to this problem.
    I have created a JTree that displays the content of a directory under a root node (displayed). I have created my own renderer to customize the labels and i use a TreeModel to add and remove nodes.
    The problem (possibly a known bug): sometimes (it actually seems to be completely random), the Ttree "fails" rendering one of the label, resulting in a big white space instead of the usual label (icon + file name). Other labels in the tree are displayed correctly. The "big white label" can be selected and correctly links to the file it represents (information about the file is displayed correctly). All in all, everything works perfectly fine except one item is displayed as a big empty label.
    Is there any chance this could be a java bug ? If not is there any way i could know what causes this failure ?
    Regards.
    NB: some friend of mine that is working on a different project has exactly the same problem and can't find a solution either.

    I am having the identical problem and its driving me crazy. This started happening to me after I installed new hard drives and reinstalled the OS. I then transfered all the old settings from the old drive. Everything else seems to work perfectly. If you get anywhere with this let me know.
    Hy
    My goal: To import some pictures into iMovie. Maby
    add ken burns efects to them, add a bit of narration
    and some music, edit everything and export.
    The problem: Let say I use the following method: i
    click Media tab, then i click photos, then i select
    the photo, and in the Photo Settings click apply.
    iMovie then imports the photo, puts it in the
    timeline and then the dark red bar bellow apears (the
    one that would means rendering). The problem is,
    there is no light red getting over it (that would
    indicate rendering in progress). It's the same if i
    click and drag a photo into the clip browser (only
    the dark red is displayed on the bottom of the
    thumbnail). If i try to quit iMovie it warns me that
    rendering is in progress.
    It doesn't matter how big a photo is (i tried
    300x200px, 800x500px, 1500x1000px, 3000x2000px) or
    what format (jpg, tiff, png).
    I tried restarting the application and the sistem. I
    created another user to try if anything changes. I
    erased the preferences. I even tried copying the
    whole application from frend's computer (the same
    version and all). The dark red bar doesn't start to
    fill red (i checked in the terminal how much
    processor does it eat and it's on 7%, so it probablly
    means it's doing nothing)
    I have a 2Ghz, 2GB of ram Macbook 13" Intel core duo.
    I have 67 GB of space left (format: Mac-os extended -
    journaled), running OS-X 10.4.8 and updated to the
    latest updates. iMovie version is 6.0.3 (267.2).
    What else is there to do? Would reinstalling the
    whole sistem help and is there a way to keep all of
    my preferences and mail accounts and contacts, … in
    case i have to do that?
    thx in advance
    Peter
    Macbook 13"  
    Mac OS X (10.4.8)  

  • JTable with JPanel form as cell renderer/editor

    I have a JTable that uses a custom cell editor/renderer. The cell editor/renderer is a JPanel form with labels and text panes. As the user edits the information, I adjust the table row height (setRowHeight) and the JPanel layout manager updates the layout on the cell editor. This all seems to work fine. However, when the user exists the cell and the cell renderer is shown, it has the correct new row height but has not been correctly layed-out for the new row height. How do I force my cell renderer to be re-layout after the editor closes?

    That does not seem to work. I have done the following:
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int r, int c)
    this.table = (EditorTable) table;
    row = r;
    column = c;
    if (isSelected)
    setBackground (Preferences.selectedRowBgColor);
    else
    setBackground (formBg);
    // constructs the panel components
    setCellValue (value);
    revalidate();
    return (this);

  • Floating Height of JTextArea (as Renderer/Editor) in a JTable Cell

    Hey Folks,
    I'm kinda struggling with JTextAreas...
    There is this JTable, which consists of three colums (practically there are two - the other one's an ID-Field...) and only one
    of them ist editable für users.
    Left column is a commentary column which has a max of 150 characters - Right column fills automaticly with a user/date stamp.                                                                                                                                                                                    
    The main function is that on showing the table, old comments will be retrieved from database and new ones can be entered.
    This works all fine and is no matter of subject...
    The core of my problem is that there seems to be no straigh-forward way of determine a proper linecount from (a wordwrapped!) JTextArea.
    After a long search in the net, i found this approach:
        private static ArrayList<String> getWrappedLines(JTextArea myTextArea) {
            ArrayList<String> linesList = new ArrayList<String>();
            int length = myTextArea.getDocument().getLength();
            int offset = 0;
            try {
                while (offset < length) {
                    int end = Utilities.getRowEnd(myTextArea, offset);
                    if (end < 0) {
                        break;
                    // Include the last character on the line
                    end = Math.min(end + 1, length);
                    String line =
                        myTextArea.getDocument().getText(offset, end - offset);
                    // Remove the line break character
                    if (line.endsWith("\n")) {
                        line = line.substring(0, line.length() - 1);
                    linesList.add(line);
                    offset = end;
            } catch (BadLocationException e) {
                System.err.println("Bad Location at TextArea");
            return linesList;
        }    This code reads the content of a JTextArea an separates wrapped lines in an array.
    With manual line breaks ("\n") I get Exceptions (Bad Location) which isn't too bad, because
    I was trying to ban manual line breaks anyway...
    The above given method retrieves the lines, while the next sets the new Height (line count multiplied by Font Height) to the row.
        public static void setOptimalRowHeight(JTable table, JTextArea textArea, int row, int column) {
            if (
                row >= 0 &&
                column == VerwaltungsnotizController.IND_VNO_NOTIZ   
                int fontHeight =
                    textArea.getFontMetrics(textArea.getFont()).getHeight();
                ArrayList<String> wrappedLines = getWrappedLines(textArea);
                int nrOfLines = wrappedLines.size();
                int oldSize = table.getRowHeight(row);
                int newSize = (fontHeight * nrOfLines) + 5;
                if (newSize != oldSize) {
                    table.setRowHeight(row, newSize);
         public static void setOptimalRowHeight(JTable table, JTextArea textArea) {
         int row = table.getSelectedRow();
         int column = table.getSelectedColumn();
         if (
              row >= 0 &&
              column == VerwaltungsnotizController.IND_VNO_NOTIZ   
              setOptimalRowHeight(table, textArea, row, column);
         }The above combined Sources are used by two classes, which are "tied" to the table.
    One is the CellEditor (which works almost fine); the other one is the CellRenderer (which fails miserably!)
    CellEditor (with Listener):
    public class VnoCellEditor extends AbstractCellEditor implements TableCellEditor {
        private VnoTextArea textArea;
        private JTable table;
        public VnoCellEditor (JTable table) {
            this.table = table;
            textArea = new VnoTextArea(table);
            textArea.setMaximumInputLength(VerwaltungsnotizController.MAX_INPUT_VNO);
            textArea.addKeyListener(new TextAreaEnterAdapter());
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
            Document document = textArea.getDocument();
            document.addDocumentListener(new VnoTextAreaDocListener(table, textArea));
        public Component getTableCellEditorComponent(JTable table, Object value,
                                                     boolean isSelected, int row,
                                                     int column) {
            if (value instanceof String) {
                textArea.setText((String)value);
            } else if (value instanceof Integer) {
                Integer intValue = (Integer)value;
                textArea.setText(intValue.toString());
            } else {
                Object objValue = value;
                textArea.setText(objValue.toString());
            System.err.println("Editor - get Component");
            return textArea;
        public Object getCellEditorValue() {
            return textArea.getText();
    public class VnoTextAreaDocListener implements DocumentListener {
        private JTable table;
        private JTextArea textArea;
        public VnoTextAreaDocListener(JTable table, JTextArea textArea) {
            this.table = table;
            this.textArea = textArea;
        public void insertUpdate(DocumentEvent e) {
            VnoTableRowHeightHelper.setOptimalRowHeight(table, textArea);
        public void removeUpdate(DocumentEvent e) {
            VnoTableRowHeightHelper.setOptimalRowHeight(table, textArea);
        public void changedUpdate(DocumentEvent e) {
            //Plain text components don't fire these events
    }As said the editor works almost as planned. On every Keystroke made in Edit-Mode of the table, insertUpdate() or removeUpdate()
    is being called, corresponding to the type of Keystroke ... (duh!)
    The Helpers method is called and the row-height is set real nicely.
    !But!
    when i navigate into an other row, a removeUpdate()-event is beeing thrown and due to the mechanism the cell selection
    gets somehow mixed around and row-heights get switched.
    Maybe this could get improved, but i don't se my error - which wouldn't be nescessary if this event wasn't thrown.
    (for what I don't see a reason anyway ... !)
    CellRenderer:
    public class VnoCellRenderer implements TableCellRenderer {
        private VnoTextArea textArea;
        private int Row = -1;
        private int Column = -1;
        private VnoTableModel jtmVno;
        public VnoCellRenderer(JTable table) {
            this.jtmVno = (VnoTableModel)table.getModel();
            textArea = new VnoTextArea(table);
            textArea.setLayout(new BorderLayout());
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
        public VnoTextArea getTextArea() {
            return textArea;
        public Component getTableCellRendererComponent(JTable table, Object value,
                                                       boolean isSelected,
                                                       boolean hasFocus, int row,
                                                       int column) {
            Row = row;
            Column = column;
            String tmpValue = null;
            if (value instanceof String) {
                tmpValue = (String)value;
            } else if (value instanceof Integer) {
                tmpValue = ((Integer)value).toString();
            } else {
                tmpValue = value.toString();
            // FARBEN:
            // Normalmodus
            if (jtmVno == null) {
                System.err.println("Table Model noch nicht initialisiert!");
                textArea.setBackground(Color.LIGHT_GRAY);
            } else {
                if (jtmVno.isCellEditable(Row, Column)) {
                    textArea.setBackground(Color.WHITE);
                } else {
                    textArea.setBackground(Color.LIGHT_GRAY);
            textArea.setForeground(Color.BLACK);
            // Für ausgewählte Zeile
            if (isSelected && !hasFocus) {
                textArea.setBackground(CommonConstants.SELECTION_COLOR_BLUE);
                textArea.setForeground(Color.WHITE);
            textArea.setText(tmpValue);
            textArea.setEditable(true);
            if (Column == VerwaltungsnotizController.IND_VNO_NOTIZ) {
                VnoTableRowHeightHelper.setOptimalRowHeight(table, textArea, row, column);
            return textArea;
    }Okay, this is where the shit hits the fan!
    Since with renderers there is no manual content mutation, row-height-settings are not done with listeners.
    I put this at the very end of the getTableCellRendererComponent(), which is called every time a cell gets rendered.
    The main problem here is that at this point my methods can't determine any linewraps at all!
    getWrappedLines() always returns an empty Array (since Utilities.getRowEnd() returns "-1" beforehand...).
    I'm afraid that my methods are called way too early - at a point were the rendering is not completed or has not even started.
    And to accomplish my desired tasks the fully rendered JTextArea would be needed ... ?!
    I have very limited swing experience, so I can only guess about this core features ...
    But i this is the case - my methods should be called later on the rendered cell. But how? from which component?
    Btw: I have written my own JTextArea to limit the input size
    public class VnoTextArea extends JTextArea {
        private JTable table;
        private int _maximumInputLength = 0;
        public VnoTextArea(JTable table) {
            this.table = table;
        public void setMaximumInputLength(int maximumInputLength) {
          if (maximumInputLength != 0) {
            _maximumInputLength = maximumInputLength;
            super.setDocument(new PlainDocument() {
                public void insertString(int offset, String string, AttributeSet attributeSet) throws BadLocationException {
                  StringBuffer buffer = new StringBuffer(string);
                  int size = VnoTextArea.this.getText().length();
                  int bufferSize = buffer.length();
                  if ((size + bufferSize) > _maximumInputLength) {
                    buffer.delete((_maximumInputLength - size), bufferSize);
                  if (size < _maximumInputLength) {
                    super.insertString(offset, buffer.toString(), attributeSet);
                  } else {
                    Toolkit.getDefaultToolkit().beep();
    }I'm sorry for not providing a running example, but it's a pretty huge project...
    Providing all dependencies would go far beyond the scope.
    (and there are many sources which I'm not allowed to post)
    But I hope my examples get down to the core of my problem!
    I also tried different approaches:
    - using getPreferredSize() of the JTextArea (seemed to do nothing useful at all?!)
    - using getLineCount/() of the TextArea (only counts "\n" ...)
    - guessing that every row consist of an average of 20 characters cumpute by myself (low-tech, buggy but fast - unsatisfying)
    With my above mentioned approach I got by far the best results (partially) - but I'm at my wits' end.
    I don't know it any better... And i have tried for days without improvement.
    What would you do?
    vielen Dank im Voraus schon mal für eventuelle Mühen,
    Haye

    no solution - just a couple of comments:
    - never ever change the calling table in a renderer, I mean really NEVER
    - instead, listen to table events and resize the row height as appropriate
    - JTextArea has a somehow weird prefSize calculation (forgot the details, so don't nail me :), so you have to manually set one dimension and then ask the area to calculate the other. In your renderer, you can do something like:
    Component getTableCellRendererComponent(....) {
        int columnWidth = table.getColumnModel().getColumn(column).getWidth();
        textArea.setSize(columnWidth, Short.MAX_VALUE);
        ... here do the normal config
    // then somewhere else, triggered by appropriate change events
    void updateRowHeight(JTable table, int row) {
       int height = table.getRowHeight();
       foreach column {
             TableCellRenderer r = table.getCellRenderer(row, column);
             Component c = table.prepareCellRenderer(r, row, column);
             height = Math.max(height, c.getPreferredSize().height);
       table.setRowHeight(row, height);
    } HTH - ein bißchen wenigstens :-)
    Jeanette

  • JTree - renderer

    When i expand a jtree node, i am populating the content in runtime. I use model.insertNodeInto() method to insert the nodes. I have a dummy node in the first position so that i can get a +, so that i can expand the jtree node. I am changing the first dummy node to a node i want using model.valueForPathChanged() method. Everything works fine. I have a renderer attached. model.insertNodeInto() calls the getTreeCellRendererComponent() method successfully. But model.valueForPathChanged() is not calling the getTreeCellRendererComponent() by default.
    My questions are:
    1. Can i call the renderer forcefully for valueForPathChanged? If so, how?
    2. Is there a easy way to get + for a node, even though the node has no child? i.e a leaf should have + , so that i can expand.
    3. I tried deleting the first node, and insert a new node in first position. But removeNodeFromParent is calling model.reload() which is causing collapse of my node.

    Best thing to do is implementing your own tree mobel
    or tree node.
    It has a method that should retun the number of
    childs a node has. When it return a value greater
    than zero you will get the + sign.I am implementing my own model. but can you help with the exact method to overload and return a value greater than 0. ?
    Thanks.

  • JTree: Cell Editor takes few click to start editing

    I have a JTree and have set the user defined renender and cell editor.
    However, user has to click continuously for some time to start the editing operation. How can I start the edit operation immediately after one click only.
    TIA
    Sachin

    ((DefaultCellEditor)myTable.getCellEditor()).setClickCountToStart(1);
    Remember that a click is a mouse press and release without moving the mouse.

  • JTree renders only 10 records

    I have a data model based on toplink and datacotrols were created on the toplink session. When I introduced a jtree bound with a data collection within datacontrol, it rendered only top ten records from the collection. When it is rendered in a jtable, all records were rendered. Any one knows why?

    Figured it out. Needs to change the rangesize.

  • JTree Rendering

    Hello! Generally, JTree is rendered like :
    +x                                                     
    -+a
    ----a1
    ----a2
    ----a3
    -+b
    ----b1
    ----b2
    Is it possible to render a JTree like (think that '-' are empty characters):
    --------------------+x
    -------------a----------b
    ------- a1-a2-a3------b1-b2
    If it is possible, How I can render a JTree in that manner?

    use this one.I think it will help u.Gd lk
    tree =new JTree(root);
    DefaultTreeCellRenderer renderer =(DefaultTreeCellRenderer)tree.getCellRenderer();
    renderer.setLeafIcon(new ImageIcon(getClass().getResource("leafimages/3.gif")));
    renderer.setClosedIcon(new ImageIcon(getClass().getResource("leafimages/1.gif")));
    renderer.setOpenIcon(new ImageIcon(getClass().getResource("leafimages/2.gif")));
    renderer.setBackgroundNonSelectionColor(new Color(15,85,134));
    renderer.setBackgroundSelectionColor(Color.YELLOW);
    renderer.setTextNonSelectionColor(new Color(217,227,227));
    renderer.setTextSelectionColor(Color.RED);
    renderer.setHorizontalTextPosition(SwingConstants.LEADING);
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    tree.setFont(new Font("Tahoma",1,12));
    tree.setBackground(new Color(15,85,134));

  • JTree renderer problem

    I have listed below a shor example.
    What I need is a method to do each cell to be as wide as the tree is (see the red border line), even if I resize the window. And ofcourse, the tree should keep a minimum width so every cell is fully shown.
    I'll be waiting for your answers. Thanks.
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    public class TreeExample extends JFrame {
        public TreeExample() {
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            getContentPane().add(new JScrollPane(new SomeTree()));
            pack();
        public static void main(String[] args) {
           SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new TreeExample().setVisible(true);
    class SomeTree extends JTree {
        public SomeTree() {
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
            String str = "***";
            for (int i = 0; i < 10; i++) {
                root.add(new DefaultMutableTreeNode(str));
                str += "***";
            setModel(new DefaultTreeModel(root));
            setCellRenderer(new SomeCellRenderer());       
            setBorder(BorderFactory.createLineBorder(Color.RED));
    class SomeCellRenderer extends JLabel implements TreeCellRenderer {
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                                                          boolean selected, boolean expanded,
                                                          boolean leaf, int row,
                                                          boolean hasFocus) {
            setOpaque(true);
            setText(value.toString());
            setBackground(Color.LIGHT_GRAY);
            return this;
    }

    The only problem i can figure is maybe the layout. Flowlayout is squeezing the size of the buttons so that they can appear in the little area that they do get. If you use borderlayout instead of the flowlayout, it may solve your problem. If that also doesn't work then set the minimum sizes of the labels.

  • JTree Renderer Question

    Hi,
    i want to change the icon of a particular leaf when the user double click it, but i dont want to change the rest of the other leafs icons i want them to keep the icon they have
    can this be posible??
    thank you

    create your own renderer.
    Search for "MyRenderer" on this page:
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

  • Holly...JTree rendering problem

    okay guy, everything is done as what i post many many forum, then finally done except!!!
    except i still want my node (may be at the child or leaf level) to be able to response to my MouseEntered event (or may be other evet). another thing is that why isn't my JLabel or JTextPane get the hyperlink (i do implement the interface) show up instead of the entire hyperlink address in the JLabel (i try to clearify at the example code down there)?
    class TreeTextArea extends JEditorPane implements MouseListener, HyperlinkListener {
    other class method here
    // following is some part of the method, line is the hyperlink address
    lblSeqHyperlink.setText("<html><font face='times new roman'><u><a href='" + line + "'>testing...</a></u></font></html>");
    lblSeqHyperlink.setEditable(false);  // i've trying to true, the same
    lblSeqHyperlink.addHyperlinkListener(this);
    add(lblSeqHyperlink);
    // another method, but no response at all
    public void mouseEntered(MouseEvent e) {
            int curType = Cursor.HAND_CURSOR;
            lblSeqHyperlink.setCursor(new Cursor(curType));
            lblSeqHyperlink.setToolTipText("testing onli...");
    }any idea? thank a lot

    Code speaks for 1000 words... ;)
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.net.*;
    public class LinkTest extends JFrame
         public LinkTest()
              super("Link test");
              String line="http://www.gempukku.com/";
              JEditorPane editorPane=new JEditorPane();
              editorPane.setContentType("text/html");
              editorPane.setText("<html><font face='times new roman'><u><a href='" + line + "'>testing...</a></u></font></html>");
              editorPane.setEditable(false);
              editorPane.addHyperlinkListener(
                        new HyperlinkListener()
                              * Called when a hypertext link is updated.
                              * @param e the event responsible for the update
                             public void hyperlinkUpdate(HyperlinkEvent e)
                                  HyperlinkEvent.EventType et=e.getEventType();
                                  if (et==HyperlinkEvent.EventType.ENTERED)
                                       setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                                  else if (et==HyperlinkEvent.EventType.EXITED)
                                       setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                                  else if (et==HyperlinkEvent.EventType.ACTIVATED)
                                       URL url=e.getURL();
                                       System.out.println("Link: "+url.toString()+" was clicked.");
              this.getContentPane().add(new JScrollPane(editorPane));
         public static void main(String[] args)
              LinkTest frm=new LinkTest();
              frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frm.setBounds(0, 0, 400, 300);
              frm.setVisible(true);
    }

Maybe you are looking for