So, I’m making a kind of text editor, and I need a JScrollPane for vertical navigation.
But I can’t get it to work.
I have read every freaking tutorial on first ten pages of google results, and I can’t get it to work.
Lets say I have JFrame (size 1000×800). I want to put a JPanel (1000×2000) in it so that it horizontally alignes with the JFrame. I want to stick a simple scroll bar to the right side of the JPanel so I can get to the rest of it.
I have reduced sizes, I have added JPanel to JScrollBar and vice versa, added one of them to JFrame, both, none, but nothing.
So, at this point, I wouldn’t mind a couple of lines of finished code…
EDIT: Fine, here’s the code…
mWindow = new JFrame(lang.getString("title"));
mWindow.setSize(1000, 800);
mWindow.setLocationRelativeTo(null);
mWindow.setResizable(false);
mWindow.setLayout(null);
mWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mWindow.setVisible(true);
workspace = new JPanel();
workspace.setBounds(0,0, 1000, 1203);
workspace.setBackground(Color.RED);
scroll = new JScrollPane(workspace, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setBounds(0, 20, 600, 600);
//scroll.setLayout(null);
mWindow.getContentPane().add(scroll);
mWindow.repaint();
mWindow.validate();
That shows a part of JPanel (600X600, (JScrollPane size)), and shows scrollbars, but isn’t scrollable
So, I did this really quick test and it works fine for me…
And the test frame
Which produces this:
On a side note, I don’t know why people insist on using null layouts, they just cause more trouble and heart ache then they’re worth. Take the time to find some simple layout managers. I hate VB for a lot of reasons, but layout management is at the top of my list, IMHO