I have wrote a code for Setting a JTable to a Panel with layout null. I tried to change its width and height and tried to set a scrollpane horizontally but there is no change
Asked
Active
Viewed 85 times
0
-
2*"..a Panel with layout null.."* 1) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Sep 28 '15 at 11:35
-
1I too wanted to try what you tried... But couldn't find a piece of code to try upon... – CoderNeji Sep 28 '15 at 11:35
-
2This usually happens because either you use a `null` layout and/or your screw with the tables `preferredSize` – MadProgrammer Sep 28 '15 at 11:37
-
panel = new JPanel(); // panel.setPreferredSize(new Dimension(800, 300)); // Create columns names String columnNames[] = { /****Column name****}; // Create some data String dataValues[][] = { //********Table Data******/ }; // Create a new table instance table = new JTable(dataValues, columnNames); table.setSize(800, 900); table.setEnabled(false); // Add the table to a scrolling pane scrollPane = new JScrollPane(table); scrollPane1 = new JScrollPane(panel); – Dcoder Sep 28 '15 at 11:39
-
Avoid using `null` layouts, pixel perfect layouts are an illusion within modern ui design. There are too many factors which affect the individual size of components, none of which you can control. Swing was designed to work with layout managers at the core, discarding these will lead to no end of issues and problems that you will spend more and more time trying to rectify. See [Laying Out Components Within a Container](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html) for more details – MadProgrammer Sep 28 '15 at 11:45
-
@Dcoder voting to close too – mKorbel Sep 28 '15 at 13:13