Is it possible to include JButton in a JTable?

后端 未结 3 1289
既然无缘
既然无缘 2021-02-08 08:05

I have a JTable that stores the results of a database query, so far so good. What I want is for the last column in each table to have a clickible JButton that will open the edit

相关标签:
3条回答
  • 2021-02-08 08:31

    Contrary to the tutorial above, there is a way to do this without a complicated positioning math, custom mouse listeners, and custom table models. Instead, it can be done with a single simple custom class following the pattern described here:

    http://web.archive.org/web/20100623105810/http://ivolo.mit.edu/post/A-Simple-Pattern-for-Embedding-Components-into-a-Swing-JTable.aspx

    0 讨论(0)
  • 2021-02-08 08:43

    Take a look at Sun's introduction to the JTable component, specifically, the section about Editors and Renderers. It discusses the use of alternative CellRenderers, and CellEditors. What you'd need to do is create (or borrow) a ButtonCellRenderer and a ButtonCellEditor and then apply them to the column in question in your JTable. The examples found in the linked articles should give you all the information you need.

    0 讨论(0)
  • 2021-02-08 08:47

    You may also find my tutorial on a similar subject (in this case, using a JPanel) helpful as well: Custom JPanel cell with JButtons in JTable

    0 讨论(0)
提交回复
热议问题