Hyperlinks in Jtable

hi,
I have a Jtable and i have written a custom cell renderer to it. The custom cell renderer class extends JeditorPane and implements TableCellRenderer. I need a Jeditor pane coz each cell contains html content which have hyperlinks and some text. I need to capture the hyperlink click event when i click on the link.
how can this be done.

Thanx for the reply,
i had seen the example which u have sent before.. i have clearly mentioned the click event is inside the table cell.
I have the Jeditor pane in each cell.. i need to capture the click event of the editorpane which is placed in side the tabel cell.
I'm not sure where I have to declare the hyperlinklistener, cause as far as I know, you can't set the listener to the JTable cause it tells me it doesn't know what the hyperlinklistener is when i try to assign it to the table.

Similar Messages

  • How to use JEditorPane in Jtable

    Hi
    I'm trying to put HyperLinks in JTable but i don't not how to add Hand Cursor when mouse is over a hyperLink and how to active it when click it.
    Thanks
    DefaultTableModel tableModel = new DefaultTableModel(new String[][]{{"<a href=www.google.com>Google</a>, <a href=www.yahoo.com>Yahoo</a>"}}, new String[]{"URL"});
    JTable table = new JTable(tableModel);
    table.setRowHeight(24);
    table.setDefaultRenderer(Object.class, new EditorPaneTableCellRenderer());
    class EditorPaneTableCellRenderer extends JEditorPane implements TableCellRenderer
    EditorPaneTableCellRenderer()
    setContentType("text/html");
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    String link = String.valueOf(value);
    setText(link);
    setBackground(isSelected? table.getSelectionBackground() : table.getBackground());
    return this;
    }

    Multi-post: http://forum.java.sun.com/thread.jspa?threadID=5273661&tstart=0

  • Method call in html anchor tag

    I have read about how to place a hyperlink in JTable cell in other threads. i have a method called Details() which has a mouse pressed event which responds on left click on the first column cells of my JTable. then i get the column and row positions and open up a JDialog.
    so Now i have to show the first column cells as hyperlinks(underlined and handcursor on visit).
    i have done something like this,
    setText( "<html><a href=\"\">" + (String)(value==null?"":value ) +"</a></html>"); this makes the cell values blue colored as well as underlined as soon as the table is loaded.
    how can i make it behave like a hyperlink ? that is colored, underlined and handcursor only when mouse is placed on it.
    Can i have the call to Details() method inside the anchor tag which i have shown above?
    Thanks,

    Well what do you know, I was doing everything correctly.
    Firefox does not allow local file links from a web page.
    http://kb.mozillazine.org/Firefox_:_Issues_:_Links_to_Local_Pages_Don%27t_Work

  • How to create Hyperlink column in a JTable

    Can anyone help in creating a hyperlink column in a JTable.
    Thanks in advance,
    Sridhar.

    If the parent is an Applet it is very simple .
    catch the mouse click on columns and execute the following code
    String url = getValueAt(i,j);
    getAppletContext().showDocument(new
    URL(url ), "_blank");
    thatz all .
    if ur program is an application use this getRuntime.exec() and use parameters to rundll32.exe url and iexplore.exe in Windows platform,
    if u have still doubts plz get back to me
    Renjith K.V

  • How do I change the colour of a selected cell in a jTable?

    I have a Jtable that displays URL names in one column. There are several problems I'm having. The effect I'm trying to achieve is this:
    When the user runs the mouse over the URL name the cursor should change into a hand (similar to what happens in an HTML hyperlink). I'm aware that the Cursor class can set the cursor graphic so i figure that i need a listener of some sort on each cell (so the cursor can change from an arrow to a hand) and also one to indicate when the cursor is not on a cell (so that it can change from a hand back into an arrow). Is this the right track?
    Also, I've looked at the DefaultTableCellRenderer class (which, as i understand it, is responsible for how each cell in the jtable is displayed) for a method that will allow me to set the background of a selected cell (or row or column). I require this because each time i select a cell (or row) it becomes highlighted in blue. I would rather it just remained white and changed the cursor to a hand. I know there exists a method for setting the background for an unselected cell but none for a selected cell. Again, I'm not sure if I'm going down the right track with this approach.
    Lastly, if the cell has been selected (by a mouse click) the font of the writing in the cell (i.e. The name of the URL) should change. This shouldn't be too much of a problem I think.
    I do not expect anyone to provide code to do all of this but some general pointers would be extremely helpful as I do not know if I'm thinking on the right track for any of this. Having some (limited) experience with Swing I doubt there is a simple way to do this but I can only hope!
    Thanks.
    Chris

    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    there you can find some examples with CellRenderer's and so on ...
    have fun

  • Hyperlink in a jtablecell

    Hi,
    I want to use a hyperlink in my jtable cell. If anyone has successfully implemented it, please let me know.

    Never done it, m'self, but it's going to be a bit awkward. I'd recommend adding your own MouseListener to the table to catch mouse clicks and respond to them, handing the clicks to the (fully functional) rendering component and modding them dependent upon row.
    Did that make any sense?

  • Jtable column name

    Hi frds,
    I developed a JTable for my java application and it is working fine but I need some modifications which i'm unable to do.my JTable is actually linked with mysql database and the data in Jtable comes from the database.my requirement is when i change data in the JTable, the change must reflect in the database.can u plz help me out..

    hi,
    if you have taken the data from the database,this means that you have no problem with java database connectivity.to inform the database you have to run some sql commands.
    http://www.cab.u-szeged.hu/local/doc/pgsql/sql-commands.html
    in the previous link you will find the sql commands.
    i think that you want update,so click the hyperlink with the name update.
    if something wrong is going wrong let me know.

  • Clickable button in jtable header

    Here is a modification of camickr code to make buttons clickable in the jtable cells. The question is how to modify it to make them clickable in the table headers. It looks like there is quite a different behavior in cells and headers (naturally it probably should be this way). More specifically, I guess my question is how do you modify MyColHeaderRenderer class in the code below. Btw, this is also an example I've mentioned in one of the previous posts when a component responds to a press mouse event but not click event when first pressed.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    * @author
    public class Example4a extends JFrame {
        MyCell[][] data = {{new MyCell("A1"), new MyCell("A2")}};
        MyColHeader[] headers = {new MyColHeader("col 1"), new MyColHeader("col 2")};
        /** Creates a new instance of Example5 */
        public Example4a() {
            setTable();
            setSize(200, 200);
            setVisible(true);
            super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void setTable() {
            DefaultTableModel model = new DefaultTableModel(data, headers){
                public Class getColumnClass(int column) {
                    return MyCell.class;
            MyTable table = new MyTable(model);       
            JScrollPane scrollpane = new JScrollPane(table);
            JPanel top_panel = new JPanel();
            top_panel.setLayout(new BorderLayout());
            getContentPane().add(top_panel);
            top_panel.add(scrollpane, BorderLayout.CENTER);
        public static void main(String[] args) {
            Example4a ex = new Example4a();
        class MyTable extends JTable {
            public MyTable(TableModel model) {
                super(model);
                MyCellRenderer cell_renderer = new MyCellRenderer();
                MyColHeaderRenderer header_renderer = new MyColHeaderRenderer();
                TableColumnModel columnModel = getColumnModel();
                for(int i=0; i<columnModel.getColumnCount(); i++) {
                    TableColumn column = columnModel.getColumn(i);
                    column.setCellRenderer(cell_renderer);
                    column.setCellEditor(cell_renderer);
                    column.setHeaderRenderer(header_renderer);
                this.setRowHeight(50);
        class MyCellRenderer extends AbstractCellEditor
                implements TableCellRenderer, TableCellEditor {
            MyCell editCell;
            public MyCellRenderer() {
            public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return (MyCell)value;
            public Component getTableCellEditorComponent(
                    JTable table, Object value, boolean isSelected, int row, int column)  {
                editCell = (MyCell)value;
                return editCell;
            public Object getCellEditorValue() {       
                return editCell;
        class MyCell extends JPanel {
            String text;
            JButton button;
            public MyCell(String text_) {
                text = text_;
                setLayout(new GridBagLayout());
                button = new JButton(text);
                button.addMouseListener(new MouseListener() {
                    public void mouseClicked(MouseEvent e) {
                        System.out.println("cell button is clicked");
                    public void mouseEntered(MouseEvent e) {                   
                    public void mouseExited(MouseEvent e) {
                    public void mousePressed(MouseEvent e) {
                        System.out.println("cell button is pressed");                   
                    public void mouseReleased(MouseEvent e) {
                add(button, new GridBagConstraints(0, 0, 1, 1, 0, 100.0
                    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 5, 10, 5), 20, 10));
        class MyColHeader extends JPanel {
            String text;
            JButton button;
            public MyColHeader(String text_) {
                text = text_;
                setLayout(new GridBagLayout());
                setBorder(BorderFactory.createEtchedBorder());
                button = new JButton(text);
                button.addMouseListener(new MouseListener() {
                    public void mouseClicked(MouseEvent e) {
                        System.out.println("column header button is clicked");
                    public void mouseEntered(MouseEvent e) {                   
                    public void mouseExited(MouseEvent e) {
                    public void mousePressed(MouseEvent e) {
                        System.out.println("column header button is pressed");                   
                    public void mouseReleased(MouseEvent e) {
                add(button, new GridBagConstraints(0, 0, 1, 1, 0, 0.0
                    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(3, 0, 3, 0), 5, 0));
        class MyColHeaderRenderer implements TableCellRenderer {
            public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return headers[column];
    }

    draw a shape and ensure it is selected
    in the Inspector > hyperlink > enable as hyperlink > click slide button and enter the slide number
    place the object in slide 2 and create a dissolve to automatically build on entry for the object

  • Giving Hyperlink

    Hi,
    How to give hyperlink for text in a page... I have created an item (Display as text does not save state), now I want to give an hyperlink to that so that it will navigate to another page. Is there any other way of doing the same..please help me.
    Regards,
    Pa

    To render those cells with an underline have your TableCellRenderer return a JTextPane set up as follows:
    // Do this once somewhere
    SimpleAttributeSet hyperlinkStyle = new SimpleAttributeSet();
    StyleConstants.setForeground(hyperlinkStyle, Color.BLUE);
    StyleConstants.setUnderline(hyperlinkStyle, true);
    public class MyRenderer implements TableCellRenderer
    JTextPane hyperlinkRenderer = new JTextPane();
    public Component getTableCellRendererComponent(JTable table,
                                                   Object value,
                                                   boolean isSelected,
                                                   boolean hasFocus,
                                                   int row,
                                                   int column)
      // When its a hyperlink cell do something like...
      hyperlinkRenderer. setText("");
      //  ...assuming toString is OK for you
      hyperlinkRenderer.getDocument().insertString(0, hyperlinkStyle, value.toString());
      return hyperlinkRenderer;
    }and for the mouse cursor add a MouseMotionListener to your JTable and implement mouseMoved(MouseEvent e). Then
    Point p = event.getPoint();
    // Locate the model coordinates under the event location
    int hitColumnIndex = columnAtPoint(p);
    int hitRowIndex = rowAtPoint(p);
    if (its a hyperlink cell)
      myJTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    else
      myJTable.setCursor(Cursor.getDefaultCursor());
    }You can either do the click with a MouseListener or by cell selection events, if that is OK.
    Hope that helps - good luck.

  • JTable: Is it possible to have different row heights on different columns?

    I am using a JTextArea to render cells in a JTable in order to wrap text. This works fine... the problem is that when the text wraps, it increases the rowHeight for that row across the entire table. I would like to be able to only increase the rowHeight for that single column.
    Basically, I am building a component that is a three-column list of Text labels... each label is a clickable thing that causes a new panel to load. I used a Jtable because of the features of highlighting, layout, listeners, etc. Maybe there is another way to do this...like build a custom component that just uses JLabel's or something.
    Thanks in advance for any advice or comments on the JTable rowHeight or my design decision.
    T.J. Herring

    Thanks for the suggestion. Our requirement is that all the text must be displayed.. so unfortunately the scroll bar won't work.
    This panel that I am building is supposed to act like a set of hyperlinks... like in a web browser. So that you can see all the text and click on the thing that you want. Although the underline functionality that is in the browser is not necessary.
    I originally thought that the Jtable would make it easy to lay out this data in that way.. but it seems to me that it might be better to build a custom component. Maybe I'll use a grid layout with jlabels... then I can simply add the highlight/selection functionality.
    I assume that I also could just wrap the list text in HTML and build a table out of it.. then display it in an JEditorPane.
    Thanks

  • Keep track of reference of a row added to Jtable

    Hello All,
    I need to keep track of reference of a row which is being added in JTable.
    Let suppose that I adds a row in JTable based on an object (instantiated of a class say FileUploader class). Now I adds a row whenever FileUploader class is being instantiated. The FileUploader Class is responsible to upload a file.
    1) Now suppose that there are 100 rows (of course based on 100 object of FileUploader class).
    2) User can remove single or multiple row (by means of cancel the process of upload or clear the row in the JTable for which file has successfully uploaded).
    3) I need to update a particular cell of JTable based on the status of a particular object of class FileUploader.
    One way of doing this is by using for loop on whole table to find out the corresponding row (based on some key taken from table). But this will make the application very slow.
    So, to do this, I need to have the reference of the row when it is being added in the JTable.
    How can I make it working? Please suggest.
    Thank you

    You are right that iterating over 100 times is not slow. But what will happen if there are 10000 rows.
    I am new to JTable. In my application, when user drag and drop some files / folder, a row is being added in the JTable to show the status of process (pending, ProgressBar, Completed or Error in one cell based on the current status of file / folder ) along with some more info in other cell ( like fileName, FromDir, ToDir, Size, and a hyperlink type text for action - clear, cancel, retry).
    Now FileUploader is an class which is responsible for uploading (it has a method upload() in it which is called by a daemon thread).
    So to update a particular cell (in which pending / ProgressBar/ etc is shown), I need to find the particular row which is showing the status of a file / folder.
    How can I do it (without iterating over these no. of times again and again).
    Is there any better approach to do this.

  • JLabel in JTable

    Hi gurus,
    I am new to GUI programming.
    I have a JTable with 3 columns and multiple rows.
    Is it possible to place the JLable component as an element in
    a cell of JTable.
    Please clarify me...

    Thanks for the reply
    I have a table with three columns and number of rows, the first column is the key value. With every key values there is additional data that need to be shown to user.
    First I want to show the strings in the first column (key column) as hyperlink, clinking on which should display additional info in a tool tip.
    If I can place a HyperlinkLabel that extends JLabel component in cells of JTable first column, I can diplay the additional info regarding that key in a dialog or in a tooltip.
    Is this possible....

  • Excel & Hyperlinking with Sharepoint

    I have a tracking document in Excel that has each entry linked to another place on Sharepoint to locate files and intranet articles. There are no formulas or other complex entries....just text and hyperlinks.
    If I open the Excel file in Sharepoint and edit it there, we have no issues.
    If I download the Excel file to my desktop...all links to other files are broken (the intranet file links remain active). When I try to access the link I receive a pop up window that states, "Cannot open the specified file."
    This is a file accessed by multiple people and used as a resource, there are well over 100 linked entries and the group would like to be able to use the file on their desktops.
    I have already found and unchecked the "Update Links on Save" option. This now allows me to download the file to the desktop, have no access to the links, and then upload it where I can then access the links again.
    Is there any way to preserve the links so they can be accessed on the desktop?
    Software Specs
    Windows 7
    Office 2010
    Explorer 8
    Thank you,
    Christine

    The links are absolute. All links are to our internal team site or to our intranet. The intranet links aren't affected.
    This wasn't an issue before the company upgraded us to Windows 7/Office 2010.
    The links are established (right click, select Hyperlink, copy/paste from browser) while the Excel file is on the desktop and all work fine there.  The Excel file is then uploaded to Sharepoint where the links continue to work. When the Excel file is
    downloaded to the desktop again...all links are broken. If I re-upload it to Sharepoint though, it is fine.
    I double checked the actual link. It reads the same on the desktop initially as it does on Sharepoint. When the file is downloaded to the desktop again it seems to be missing the first half of it. What function could be editing the link?
    Christine

  • A problem with hyperlinks in my Interactive PDF on smartphones...

    I hope someone can help...  I exported both an interactive and for print PDF from inDesign.  When I view the PDFs on my pc the hyperlinks that I've made in the document work perfectly fine.  When I view the PDFs on my smartphone, the hyperlinks don't work.  I've gone through many forums to make sure all my settings were correct and have tried many different things to try to get them to work, but still no luck.  Has anyone come across this issue?  Is there any way to get these hyperlinks to work on a smartphone?

    Interactive PDFs on mobile devices are nothing short of a crapshoot.
    The readers are hit or miss and the better ones require payment.
    I wish I had better news for you but right now, that’s the way it is.
    Bob

  • Report navigation after creating hyperlink

    Hi,
    I am using Webi rich clinet XI R3.1. I have one main report with six dashboards and associated detailed reports. I created hyperlink for each of the dashboard and linked to detailed report in infoview.
    If i need to see main report i've to close this detailed report.Now how can i make the detailed report open in same window and navigate forward and backward to the main report instead of closing.
    I would appreciate if some one could provide any work around available if possible atleast.
    Thanks,
    Eswar

    Hi
    Create two links one Back and one Next in each report.
    Drag two free standing cells in the report and use opendocument syntax to create the links.
    The thread Re: Hyperlink Back functionality may give an idea.
    Regards

Maybe you are looking for

  • USB drive no longer works after system reinstallation

    Recently I reinstalled the system (after 1 year of no uptades). One of my USB disks (strictly speaking it is a 2.5" disk in a USB enclosure) stopped to work. When I connect the USB cable the drive icon doesn't appear on the desktop. I attach the dmes

  • Acrobat 9 Pro - Combine files dialog box - order of files

    Hi! For my job, I need to combine files into a single PDF that are numbered a certain way, but the way Acrobat orders these files mixes them up when I try to sort by name. For example, it orders them as 09-12167-1, 09-12167-10, 09-12167-11 and so on.

  • Can't connect any BB10 device to my Mac

    After I installed the MacBook pro EFI Firmware Update 1.3, none of our devices (we have a few of them running on all released OS's) would connect to my Mac. I'm running the latest BB Link (1.1.1.39) and sometimes I see that the device connects and di

  • Text not found for item line in PO

    Hi, When creating an item line in ME23N, I get the error message: TEXT ID Z155 language EN not found. When are these texts maintained ?

  • Cannot print with authentication from acrobat pro on osx

    My company has a printer that requires authentication in the form of a 5 digit "account code", which is entered into the print driver installed on my laptop (OSX 10.9).  My printer service company has saved the account code in my print driver so that