JTable and JScrollPane

Discussion in 'Java' started by helmut.teichmann@opb.de, Jul 17, 2007.

  1. Guest

    Hi,

    a very small demo to tell you my problem (I use Java 1.6).
    I have a JTable with 11 columns in a smaller JScrollPane.
    The problem is, that I can't put the column "10" between the columns
    "8" and "9" with the mouse. It scrolls to the first column.
    What is wrong with the JScrollPane.
    It works fine with older versions of Java.

    Who can help me?

    ####################

    import java.awt.BorderLayout;
    import javax.swing.*;

    public class FixedTable
    {
    public static void main(String args[])
    {
    final Object rowData[][] = { { "1", "a", "b", "c", "d", "e", "f",
    "g", "h", "i", "j" } };
    final String columnNames[] = { "#", "1", "2", "3", "4", "5", "6",
    "7", "8", "9", "10" };
    TableModel mainModel = new AbstractTableModel()
    {
    public final static long serialVersionUID = 20003l;

    public int getColumnCount()
    {
    return columnNames.length - 1;
    }

    public String getColumnName(int column)
    {
    return columnNames[column + 1];
    }

    public int getRowCount()
    {
    return rowData.length;
    }

    public Object getValueAt(int row, int column)
    {
    return rowData[row][column + 1];
    }
    };
    JTable mainTable = new JTable(mainModel);
    mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(mainTable);
    JFrame frame = new JFrame("Fixed Table");
    frame.setResizable(false);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
    }
    }
     
    , Jul 17, 2007
    #1
    1. Advertising

  2. timjowers Guest

    On Jul 17, 10:18 am, wrote:
    > Hi,
    >
    > a very small demo to tell you my problem (I use Java 1.6).
    > I have a JTable with 11 columns in a smaller JScrollPane.
    > The problem is, that I can't put the column "10" between the columns
    > "8" and "9" with the mouse. It scrolls to the first column.
    > What is wrong with the JScrollPane.
    > It works fine with older versions of Java.
    >
    > Who can help me?
    >
    > ####################
    >
    > import java.awt.BorderLayout;
    > import javax.swing.*;
    >
    > public class FixedTable
    > {
    > public static void main(String args[])
    > {
    > final Object rowData[][] = { { "1", "a", "b", "c", "d", "e", "f",
    > "g", "h", "i", "j" } };
    > final String columnNames[] = { "#", "1", "2", "3", "4", "5", "6",
    > "7", "8", "9", "10" };
    > TableModel mainModel = new AbstractTableModel()
    > {
    > public final static long serialVersionUID = 20003l;
    >
    > public int getColumnCount()
    > {
    > return columnNames.length - 1;
    > }
    >
    > public String getColumnName(int column)
    > {
    > return columnNames[column + 1];
    > }
    >
    > public int getRowCount()
    > {
    > return rowData.length;
    > }
    >
    > public Object getValueAt(int row, int column)
    > {
    > return rowData[row][column + 1];
    > }
    > };
    > JTable mainTable = new JTable(mainModel);
    > mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    > JScrollPane scrollPane = new JScrollPane();
    > scrollPane.setViewportView(mainTable);
    > JFrame frame = new JFrame("Fixed Table");
    > frame.setResizable(false);
    > frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    > frame.setSize(300, 150);
    > frame.setVisible(true);
    > }
    >
    > }


    You're right. That's busted in Java6. Did you find the bug yet? Surely
    due to size calculation bug as commenting
    //frame.setResizable(false);
    and resizing larger than columns then it works fine.

    TimJowers
     
    timjowers, Jul 18, 2007
    #2
    1. Advertising

  3. timjowers Guest

    On Jul 17, 10:18 am, wrote:
    > Hi,
    >
    > a very small demo to tell you my problem (I use Java 1.6).
    > I have a JTable with 11 columns in a smaller JScrollPane.
    > The problem is, that I can't put the column "10" between the columns
    > "8" and "9" with the mouse. It scrolls to the first column.
    > What is wrong with the JScrollPane.
    > It works fine with older versions of Java.
    >
    > Who can help me?
    >
    > ####################
    >
    > import java.awt.BorderLayout;
    > import javax.swing.*;
    >
    > public class FixedTable
    > {
    > public static void main(String args[])
    > {
    > final Object rowData[][] = { { "1", "a", "b", "c", "d", "e", "f",
    > "g", "h", "i", "j" } };
    > final String columnNames[] = { "#", "1", "2", "3", "4", "5", "6",
    > "7", "8", "9", "10" };
    > TableModel mainModel = new AbstractTableModel()
    > {
    > public final static long serialVersionUID = 20003l;
    >
    > public int getColumnCount()
    > {
    > return columnNames.length - 1;
    > }
    >
    > public String getColumnName(int column)
    > {
    > return columnNames[column + 1];
    > }
    >
    > public int getRowCount()
    > {
    > return rowData.length;
    > }
    >
    > public Object getValueAt(int row, int column)
    > {
    > return rowData[row][column + 1];
    > }
    > };
    > JTable mainTable = new JTable(mainModel);
    > mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    > JScrollPane scrollPane = new JScrollPane();
    > scrollPane.setViewportView(mainTable);
    > JFrame frame = new JFrame("Fixed Table");
    > frame.setResizable(false);
    > frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    > frame.setSize(300, 150);
    > frame.setVisible(true);
    > }
    >
    > }


    Not fixed in Java6 Update 2.
     
    timjowers, Jul 19, 2007
    #3
  4. timjowers Guest

    On Jul 17, 10:18 am, wrote:
    > Hi,
    >
    > a very small demo to tell you my problem (I use Java 1.6).
    > I have a JTable with 11 columns in a smaller JScrollPane.
    > The problem is, that I can't put the column "10" between the columns
    > "8" and "9" with the mouse. It scrolls to the first column.
    > What is wrong with the JScrollPane.
    > It works fine with older versions of Java.
    >
    > Who can help me?
    >
    > ####################
    >
    > import java.awt.BorderLayout;
    > import javax.swing.*;
    >
    > public class FixedTable
    > {
    > public static void main(String args[])
    > {
    > final Object rowData[][] = { { "1", "a", "b", "c", "d", "e", "f",
    > "g", "h", "i", "j" } };
    > final String columnNames[] = { "#", "1", "2", "3", "4", "5", "6",
    > "7", "8", "9", "10" };
    > TableModel mainModel = new AbstractTableModel()
    > {
    > public final static long serialVersionUID = 20003l;
    >
    > public int getColumnCount()
    > {
    > return columnNames.length - 1;
    > }
    >
    > public String getColumnName(int column)
    > {
    > return columnNames[column + 1];
    > }
    >
    > public int getRowCount()
    > {
    > return rowData.length;
    > }
    >
    > public Object getValueAt(int row, int column)
    > {
    > return rowData[row][column + 1];
    > }
    > };
    > JTable mainTable = new JTable(mainModel);
    > mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    > JScrollPane scrollPane = new JScrollPane();
    > scrollPane.setViewportView(mainTable);
    > JFrame frame = new JFrame("Fixed Table");
    > frame.setResizable(false);
    > frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    > frame.setSize(300, 150);
    > frame.setVisible(true);
    > }
    >
    > }


    Works for me in Java 5 and fails in java 6 and Java 6 Update 2.
     
    timjowers, Jul 19, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Happy Day
    Replies:
    5
    Views:
    8,238
    Rogan Dawes
    Aug 17, 2005
  2. Tintin92
    Replies:
    1
    Views:
    1,777
    Andrew Thompson
    Feb 14, 2007
  3. Allan Valeriano

    Set size of JTable inside a JScrollPane

    Allan Valeriano, Jun 15, 2007, in forum: Java
    Replies:
    1
    Views:
    13,289
    Andrew Thompson
    Jun 16, 2007
  4. yashiro

    Jscrollpane and jtable

    yashiro, May 17, 2008, in forum: Java
    Replies:
    2
    Views:
    1,992
    Jeff Higgins
    May 17, 2008
  5. Haircuts Are Important
    Replies:
    3
    Views:
    384
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page