Guest User

Untitled

a guest
Oct 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public static void main(String args[]) {
  2. JFrame frame = new JFrame();
  3. frame.setSize(450, 250);
  4.  
  5. JTable table = new JTable(2, 1);
  6.  
  7. TableColumn testColumn = table.getColumnModel().getColumn(0);
  8.  
  9. JComboBox<String> comboBox = new JComboBox<String>();
  10. comboBox.addItem("Item1");
  11. comboBox.addItem("Item2");
  12. comboBox.addItem("Item3");
  13. testColumn.setCellEditor(new DefaultCellEditor(comboBox));
  14.  
  15. comboBox.addItemListener(new ItemListener(){
  16. @Override
  17. public void itemStateChanged(ItemEvent e) {
  18. if (e.getStateChange() == ItemEvent.SELECTED){
  19. System.out.println(table.getValueAt(0, 0));
  20. }
  21. }
  22. });
  23.  
  24. frame.add(table);
  25. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26. frame.setVisible(true);
  27. }
Add Comment
Please, Sign In to add comment