This discussion is archived
1 2 Previous Next 25 Replies Latest reply: Apr 17, 2013 12:59 PM by 829909 Go to original post RSS
  • 15. Re: JTable
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    BusMan29 wrote:
    I am sorry that I do not know what is SSCCE?
    Could you tell me more about it?
    http://sscce.org/

    bye
    TPD
  • 16. Re: JTable
    851498 Newbie
    Currently Being Moderated
    Simply, may I know how to add a JButton to JTable?
    I have searched the Internet.
    It included the cell renderer which is very complicated.

    Is there any simplier way to do what I need.
    Thank you.
  • 17. Re: JTable
    851498 Newbie
    Currently Being Moderated
    A table is created at the begininng. When we continue to add the data to the table, the array to store the data will be added up. So, it may exceed the original created size. Is there any conflict?

    Moreover, could someone give me some guidance on coding the JButton in Jtable?

    Any help would be appreciated.
  • 18. Re: JTable
    thomas.behr Newbie
    Currently Being Moderated
    BusMan29 wrote:
    1. May I add a JButton at the end of each row in JTable?
    I would like to add a JButton at the end of each row. When we click this JButton, the whole row is deleted.
    Well, I guess it is possible but it is quite uncommon to do this. Usually, you have a "Delete" button outside the table that simply deletes the selected row. If you absolutely do not want to go the usual way, I would still suggest not to go with a button in each row. Instead, add an additional column to your table model that simply holds the String "Delete" (or a nice icon) for all rows. Additionally, add a MouseListener to your JTable and in that listener's mouseClicked method compute the clicked table cell (JTable provides the necessary methods to do so) and if a cell in the last column was clicked, remove the corresponding row. This saves you the hazzle of writing possibly complicated TableCellRenderer and TableCellEditor implementations to make JButtons work in JTable.
  • 19. Re: JTable
    851498 Newbie
    Currently Being Moderated
    Thomas, thank for your suggestion.
  • 20. Re: JTable
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    thomas.behr wrote:
    This saves you the hazzle of writing possibly complicated TableCellRenderer and TableCellEditor implementations to make JButtons work in JTable.
    <tt>TableCellRenderer</tt> is the intended way to do this kind of stuff. And once you undertdood how <tt>TableCellEditor</tt> work it's not complicated at all.

    bye
    TPD
  • 21. Re: JTable
    851498 Newbie
    Currently Being Moderated
    Suppose I would like to delete a row in JTable, how may I do it other than adding a JButton at the end of the JTable?
  • 22. Re: JTable
    rukbat Guru Moderator
    Currently Being Moderated
    Moderator Action:
    Nothing in this thread has anything to do with why you chose to post it to the New To Java forum.

    When you have a JDeveloper question, you should choose the JDeveloper forum.

    ...locking...
    (It will likely be deleted as being utterly off-topic for this forum.)
  • 23. Re: JTable
    PhHein Guru Moderator
    Currently Being Moderated
    Mod: Reopened. Moving to Swing
  • 24. Re: JTable
    thomas.behr Newbie
    Currently Being Moderated
    BusMan29 wrote:
    Suppose I would like to delete a row in JTable, how may I do it other than adding a JButton at the end of the JTable?
    That kind of question cannot be exhaustively answered, because there can be any number of triggers for removing rows in a JTable.
    You could have a button anywhere in your GUI that removes a selected row, you could create a key binding (typically for the DELETE key) that removes a selected row, or both (if you are looking for typical ways to do so in response to user interaction).
  • 25. Re: JTable
    829909 Newbie
    Currently Being Moderated
    Regarding the frozen columns, otherwise known as fixed columns, you can find an example of leading fixed columns here: http://www.java2s.com/Code/Java/Swing-Components/FixedTableColumnExample.htm

    And a button table example here: http://www.java2s.com/Code/Java/Swing-Components/ButtonTableExample.htm
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points