How to get horizontal scroll in JTable
I have 2 issue that i need to ask, 1st how to get the horizontal scroll for my JTable, currently it shrink all the columns which is not readable at all. I have 20 columns to show in a Table.
2nd, how to adjust my table height width maximum to my screen size.
my current code is
Container cp = getContentPane(); ConnectionDB con = new ConnectionDB(); tableModel = con.getRecord(DEFAULT_QUERY); table = new JTable(tableModel); table.setPreferredScrollableViewportSize(new Dimension(900, 500)); table.setFont(new Font("Tahoma", Font.PLAIN, 12)); scrollPane = new JScrollPane(table); centerPanel.add(scrollPane, BorderLayout.CENTER); centerPanel.setBorder(BorderFactory.createTitledBorder("Books:")); cp.add("Center", centerPanel);
Kindly help me in it, Thanks in Advance.
To prevent that all columns are resized to the ScrollPane size you can disable the auto resize:
Adding your ScrollPane to the center of the BorderLayout should set the maximum size to the screen size, because normally the JFrame can't become bigger.
To set the size of the ScrollPanes ViewPort to the screen size you can use the awt Toolkit.