The easiest way would be to use JComponent#setComponentPopupMenu
You will also want to take a look at How to use menus
Question
into something like this when I right click the row.after I clicked view profile it will popup and new jFrame and display his profile. i am using GUI builder. sorry for being noob. i'm still beginner.it's hard to find on google how to do right click thing.
UPDATE2
I created the menu now but how to get the Student ID cell only... this is my code
JMenuItem item = new JMenuItem("View Profile");
JMenuItem item2 = new JMenuItem("Delete");
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(studentList.this, "Testing");
}
});
jPopupMenu1.add(item);
jPopupMenu1.add(item2);
and on my MouseReleased
private void tableMouseReleased(java.awt.event.MouseEvent evt) {
int r = table.rowAtPoint(evt.getPoint());
if (r >= 0 && r < table.getRowCount()) {
table.setRowSelectionInterval(r, r);
} else {
table.clearSelection();
}
int rowindex = table.getSelectedRow();
if (rowindex < 0) {
return;
}
if (evt.isPopupTrigger() && evt.getComponent() instanceof JTable ) {
jPopupMenu1.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
Solution
The easiest way would be to use JComponent#setComponentPopupMenu
You will also want to take a look at How to use menus