My question is how can I make the hyperlinks from a JXTable column (just for one/specific column) to action like "_blank" links of my default desktop web browser.
I use JXTable and a DefaultTableModel, also I call the data from a sqlite database. I made the research on the internet, google, [...] and I found a lot of information which says, If I don't make a mistake:
- registering a MouseListener to JXTable;
- generate point object from MouseEvent;
- get the text via getValueAt
***Note: The column have just 1 link per cell, without any text, just the link.
For now I have implemented this code to make an action where a cell is double clicked. Please someone can help me to implement a column hyperlinks which opening in default browser like in this example (but I don't know how to adapt because the data are not called from a database).
Table_Employee.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
JXTable target = (JXTable)e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
JFrame newFrame = new JFrame(); //I want to open an distinc link
newFrame.setTitle("Detail Screen"); //for every cell along one column
newFrame.setVisible(true); //in the web browser, not a frame.
}
}
});
EDIT 1 The code from EDIT 2 of @Kleopatra have some issues for my application. Also, I made another try like the code bellow, and voila - the links are there when first click is involved, but don't react (no browser open). @Kleopatra, can you provide me more information about your suggestion, because when I'm trying to put that code, the IDE don't recognize hyperlinkColumn.
Table_Employee.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
JXTable target = (JXTable)e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
AbstractHyperlinkAction<Object> simpleAction = new AbstractHyperlinkAction<Object>(null) {
public void actionPerformed(ActionEvent e) {
//open the browser event?
}
};
TableCellRenderer renderer = new DefaultTableRenderer(
new HyperlinkProvider(simpleAction));
Table_Employee.getColumnExt(2).setEditable(false);
Table_Employee.getColumnExt(2).setCellRenderer(renderer);
}
}
});