Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

JTable and JScrollPane

Thread view: 
helmut.teichmann@opb.de - 17 Jul 2007 15:18 GMT
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);
    }
}
timjowers - 18 Jul 2007 23:25 GMT
On Jul 17, 10:18 am, helmut.teichm...@opb.de wrote:
> Hi,
>
[quoted text clipped - 56 lines]
>
> }

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 - 19 Jul 2007 00:03 GMT
On Jul 17, 10:18 am, helmut.teichm...@opb.de wrote:
> Hi,
>
[quoted text clipped - 56 lines]
>
> }

Not fixed in Java6 Update 2.
timjowers - 19 Jul 2007 13:35 GMT
On Jul 17, 10:18 am, helmut.teichm...@opb.de wrote:
> Hi,
>
[quoted text clipped - 56 lines]
>
> }

Works for me in Java 5 and fails in java 6 and Java 6 Update 2.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.