Q:

Horizontal Scrolling + JTable + Java

I checked the questions on stackoverflow concerning getting horizontal scrolling on a JTable to work.  Setting AUTO_RESIZE_OFF does get me the horizontal scroll bar but at the same time the table does not utilize the full width of the scroll pane. 
I did some reading and it turns out this has been a running bug since 1998 (Will Oracle fix this?) 
I saw some suggestions about over riding methods etc but none worked for me.  So does anyone have an answer?  It would be much appreciated.  Basically I need the table to auto resize but enable the horizontal scroll bar before any of the column names get compressed. 
Thanks. 

A:

after ranting against the other answers - JXTable (in the SwingX project) has an additional column layout property which

fills the horizontal viewport (that is increases the column width) if their combined pref is less than the current width, respecting the autoResizeMode 
keeps the column sizes at their pref and shows the horizontal scrollbar if their combined pref is greater than the current width

There's a bit of internal tweaking needed, so (biased me) would suggest to use the JXTable.  Or have a look at its code and c&p - all allowed, all open source :-)

A:

Check this link and try to solve this problem
http://www.daniweb.com/software-development/java/threads/29263
JTable with horizontal scrollbar
import javax.swing.*; 
import javax.swing.table.*; 
import java.awt.*; 

public class ScrollableJTable {

    public static void main(String[] args) {
        new ScrollableJTable();
    }

    public ScrollableJTable() {
        JFrame frame = new JFrame("Creating a Scrollable JTable!"); 
        JPanel panel = new JPanel();
        String data[][] = {
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"},
            {"001", "vinod", "Bihar", "India", "Biology", "65", "First"},
            {"002", "Raju", "ABC", "Kanada", "Geography", "58", "second"},
            {"003", "Aman", "Delhi", "India", "computer", "98", "Dictontion"},
            {"004", "Ranjan", "Bangloor", "India", "chemestry", "90", "Dictontion"}
        };
        String col[] = {"Roll", "Name", "State", "country", "Math", "Marks", "Grade"};
        JTable table = new JTable(data, col);
        table.setAutoResizeMode(JTable. AUTO_RESIZE_OFF);
        JTableHeader header = table.getTableHeader();
        header.setBackground(Color.yellow);
        JScrollPane pane = new JScrollPane(table);
        panel.add(pane);
        frame.add(panel);
        frame.pack();
//        frame.setSize(500, 200);
//        frame.setUndecorated(true);
//        frame.getRootPane().setWindowDecorationStyle(JRootPane. PLAIN_DIALOG);
        frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

