JTable scrolling issue

Discussion in 'Java' started by Ray.Jaramillo, Mar 12, 2007.

  1. I have a JTable in a JScrollPane but I do not want the first two
    colums to scroll when I move the scroll bar. I want the first two
    columns to stay on the screen and the rest of the columns in my JTable
    to scroll. Is there any way to make the first two columns permanent??
    I have looked around and can't seem to come up with any answer besides
    putting them in seperate JScrollPanes, but I want the scroll bar to
    span the entire Pane.

    Thank you ahead for any help,

    Ray.Jaramillo, Mar 12, 2007
    1. Advertisements

  2. Ray.Jaramillo

    Daniel Pitts Guest

    I'm not quite sure what your asking... Perhaps you want two tables,
    one that scrolls and one that doesn't?

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(permanentTable, BorderLayout.WEST);
    panel.add(new JScrollPane(scrollingTable), BorderLayout.CENTER);
    Daniel Pitts, Mar 13, 2007
    1. Advertisements

  3. Somewhere in the JTable class, there is a protected method that prepares
    the table for a scroll pane (something along the lines of
    prepareTable()). If you fiddle with that and ColumnModels, you should be
    able to get what you want.
    Joshua Cranmer, Mar 13, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.