Showing posts with label swing. Show all posts
Showing posts with label swing. Show all posts
Sunday, January 15, 2017
How to create jTable right click popup menu Java Swing GUI
How to create jTable right click popup menu Java Swing GUI
jTable right-click popup menu Java Swing GUI - Mouse click
Java 2016
table_6.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e)
{
int r = table_6.rowAtPoint(e.getPoint());
if (r >= 0 && r < table_6.getRowCount()) {
table_6.setRowSelectionInterval(r, r);
} else {
table_6.clearSelection();
}
//row index is found...
int rowindex = table_6.getSelectedRow();
if (rowindex < 0)
return;
if (e.isPopupTrigger() && e.getComponent() instanceof JTable ) {
JPopupMenu popup = createYourPopUp(rowindex,table_6);
popup.show(e.getComponent(), e.getX(), e.getY());
}
}
});jTable right-click popup menu Java Swing GUI - Method
Java 2016
public static JPopupMenu createYourPopUp(int rowindex, JTable table_6)
{
JPopupMenu popup=new JPopupMenu();
JMenuItem edit=new JMenuItem("Edit Details");
JMenuItem delete=new JMenuItem("Delete Details");
edit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, "Edit scucessfuly");
}
});
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null, "Delete scucessfuly");
}
});
popup.add(edit);
popup.add(delete);
return popup;
}


Available link for download
Sunday, December 4, 2016
Hà m xóa dữ liá»u vá»i Jcheckbox trong Jtable Delete checkbox table Java Swing Gui Eclipse
Hà m xóa dữ liá»u vá»i Jcheckbox trong Jtable Delete checkbox table Java Swing Gui Eclipse




Hàm xóa d? li?u table khi dùng checkbox
Java 2016
public void deleteSinhVien(JTable table){
boolean tich = false;
Object[] options = { "Yes", "No" };
int n = JOptionPane.showOptionDialog(null, "B?n có mu?n xóa d? li?u này không?", "Confirm to Delete?",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
if (n == 0) // Confirm Delete = Yes
{
for (int i = 0; i < table.getRowCount(); i++) {
Boolean chkDel = Boolean.valueOf(table.getValueAt(i, 0).toString()); // Checked
if (chkDel) // Checked to Delete
{
// Delete Data
String sql = "DELETE FROM project.sinhvien WHERE idsv = ?";
try {
stmt = conn.prepareStatement(sql);
stmt.setString(1, table.getValueAt(i, 1).toString());
stmt.executeUpdate();
tich = true;
} catch (Exception ed) {
JOptionPane.showMessageDialog(null, "Không th? xóa id "
+ table.getValueAt(i, 1).toString() + " vui lòng xem l?i b?ng ?i?m");
tich = false;
}
}
}
if (tich) {
JOptionPane.showMessageDialog(null, "Xóa d? li?u thành công!");
}
}
}
Available link for download
Subscribe to:
Posts (Atom)