This discussion is archived
1 2 Previous Next 25 Replies Latest reply: Apr 17, 2013 12:59 PM by 829909 RSS

JTable

851498 Newbie
Currently Being Moderated
Is it possible to code a function like Microsoft Office Excel to Freeze a columns? e.g. I would like to freeze the first and last columns of a JTable.

How to create a JCheckBox in the last column and make it editable. And other columns are not able to edit.

Any response will be appreciated.

Edited by: BusMan29 on Mar 23, 2013 5:08 PM

Edited by: BusMan29 on Mar 26, 2013 9:27 PM
  • 1. Re: JTable
    rp0428 Guru
    Currently Being Moderated
    >
    Is it possible to code a function like Microsoft Office Excel to Freeze a columns? e.g. I would like to freeze the first and last columns of a JTable.

    How to create a JCheckBox in the last column and make it editable. And other columns are not able to edit.
    >
    No one has access to your JTable except through the code you provide. If your 'isCellEditable(int row, int col)' function returns false then that cell cannot be edited; if the function returns true then it CAN be edited.

    Go through the 'How to Use Tables' in The Java Tutorials'. It has examples of how to use the functionality.
    http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
    >
    How to Use Tables
    With the JTable class you can display tables of data, optionally allowing the user to edit the data. JTable does not contain or cache data; it is simply a view of your data. Here is a picture of a typical table displayed within a scroll pane:

    The rest of this section shows you how to accomplish some common table-related tasks. Here are the topics this section covers:

    Creating a Simple Table
    Adding a Table to a Container
    Setting and Changing Column Widths
    User Selections
    Creating a Table Model
    Listening for Data Changes
    Firing Data Change Events
    Concepts: Editors and Renderers
    Using Custom Renderers
    Specifying Tool Tips for Cells
    Specifying Tool Tips for Column Headers
    Sorting and Filtering
    Using a Combo Box as an Editor
    Using Other Editors
    Using an Editor to Validate User-Entered Text
    Printing
    Examples that Use Tables
  • 2. Re: JTable
    851498 Newbie
    Currently Being Moderated
    Thank you very much.
    I have read the tutorial.
    I found that I cannot show the header and the JCheckBox in the JTable by using the Java code.
    May I post the screen capture to this forum?

    Moreover, I cannot find the Freeze Screen function in JTable. Is JTable have this function?
  • 3. Re: JTable
    Kayaman Guru
    Currently Being Moderated
    BusMan29 wrote:
    Moreover, I cannot find the Freeze Screen function in JTable. Is JTable have this function?
    Classes rarely have such high level methods. It wouldn't be very effective. It doesn't mean that the same effect couldn't be achieved however, you just need to write the code yourself.
    I'd advise on reading the Swing tutorial to understand how Swing works first.
  • 4. Re: JTable
    851498 Newbie
    Currently Being Moderated
    I just want to freeze the first and the last columns. Is it possible?

    Moreover, I just use the code provide from the tutorial and I do not know why it could not show the header and the JCheckBox as the code should show.

    Anyone could help would be appreciated. Many thanks.

    Edited by: BusMan29 on Mar 26, 2013 9:28 PM
  • 5. Re: JTable
    Kayaman Guru
    Currently Being Moderated
    BusMan29 wrote:
    I just want to freeze the first and the last columns. Is it possible?
    Probably with custom rendering at least. But the issue here is can you do it, without having someone write the code for you? It's somewhat advanced, and if you're new to java, it might be difficult for you.
    Moreover, I just use the code provide from the tutorial and I do not know why it could not show the header and the ComboBox as the code should show.
    Hard to say, are there any exceptions? Are you absolutely sure you're running the same code as in the example? Even examples have bugs sometimes.
  • 6. Re: JTable
    gimbal2 Guru
    Currently Being Moderated
    Kayaman wrote:
    I'd advise on reading the Swing tutorial to understand how Swing works first.
    Am I blind or is the "visual index to Swing components" or whatever it was called part of the tutorial missing in action?

    http://docs.oracle.com/javase/tutorial/uiswing/

    I would have expected it to be under "using swing components" :s
  • 7. Re: JTable
    851498 Newbie
    Currently Being Moderated
    Thanks for your reply. I had added the JTable to a JPanel by using BorderLayout and add it to the Container. But, it do not show the header.
  • 8. Re: JTable
    851498 Newbie
    Currently Being Moderated
    Sorry! I had made some of the mistakes and are corrected and bold. Thank you for your attention.

    I found that the [Oracle Java JTable Tutorial|http://docs.oracle.com/javase/tutorial/uiswing/components/table.html] have the same problem too. The 1st demo could not show the JCheckBox while others does. Any of you have the same problem too?

    Many thanks.
  • 9. Re: JTable
    PhHein Guru Moderator
    Currently Being Moderated
    BusMan29 wrote:
    Sorry! I had made some of the mistakes and are corrected and bold. Thank you for your attention.

    I found that the [Oracle Java JTable Tutorial|http://docs.oracle.com/javase/tutorial/uiswing/components/table.html] have the same problem too. The 1st demo could not show the JCheckBox while others does. Any of you have the same problem too?

    Many thanks.
    The tutorial says so:
    The advantage of these constructors is that they are easy to use. However, these constructors also have disadvantages:
    They automatically make every cell editable.
    They treat all data types the same (as strings). For example, if a table column has Boolean data, the table can display the data in a check box. However, if you use either of the two JTable constructors listed previously, your Boolean data > is displayed as a string. You can see this difference in the Vegetarian column of the previous figure.
  • 10. Re: JTable
    851498 Newbie
    Currently Being Moderated
    Thank you for youe reply. I've got it.
    But, any idea on JTable not showing the header.
  • 11. Re: JTable
    851498 Newbie
    Currently Being Moderated
    The problem is fixed.
    Thank you.
  • 12. Re: JTable
    851498 Newbie
    Currently Being Moderated
    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.

    2. Is there any limitation in using the JScrollPane? Horizontal or vertical?
    The cells could not show all the digits in my 2x rows. Is there any ways to show all the digits in cells as the data in cells are digits mainly. It is very inconvenience to adjust the width of cells every time. Also, I found that the horizontal scroll bar is not shown in JTable.

    Any help would be appreciated.

    Edited by: BusMan29 on Apr 4, 2013 10:00 PM

    Edited by: BusMan29 on Apr 4, 2013 10:03 PM

    Edited by: BusMan29 on Apr 5, 2013 8:14 AM

    Edited by: BusMan29 on Apr 6, 2013 12:17 AM
  • 13. Re: JTable
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    BusMan29 wrote:
    1. May I add a JButton at the end of each row in JTable?
    aybe this could be your solution:
    http://stackoverflow.com/questions/978865/footer-row-in-a-jtable
    2. Is there any limitation in using the JScrollPane?
    Horizontal or vertical. The cells could not show all the digits.
    It did not show the horizontal scroll bar in JTable.
    Could you please give a SSCCE?

    bye
    TPD
  • 14. Re: JTable
    851498 Newbie
    Currently Being Moderated
    I am sorry that I do not know what is SSCCE?
    Could you tell me more about it?
1 2 Previous Next

Legend

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