I have created a demo by swing and I want to show full text in textarea. I want to add two textarea into a scroll bar to show all component within a scroll bar. So to do that, I create a panel and then add two textarea on this one and then I add this panel into scroll bar. When I running demo, it show correctly and it also show correctly when I resize window larger but it have problem when I resize smaller screen. It does not wrap the text when resize the screen smaller (instead of appearing horizontal scroll bar). Can you help me to automatically wrapped when resize the screen smaller.
Here my code: JPanel gui = new JPanel(new GridLayout()); gui.setBorder(new EmptyBorder(2, 3, 2, 3));
JTextArea area = new JTextArea("JTextArea on JPanel inside JScrollPane does not resize properly");
area.setWrapStyleWord(true);
area.setLineWrap(true);
gui.add(area);
JTextArea area1 = new JTextArea("JTextArea on JPanel inside JScrollPane does not resize properly");
area1.setWrapStyleWord(true);
area1.setLineWrap(true);
gui.add(area1);
gui.setBackground(Color.WHITE);
JScrollPane scroller = new JScrollPane(gui);
//scroller.setBorder(new EmptyBorder(2, 3, 2, 3));
JFrame f = new JFrame("Big Text Fields");
f.add(scroller,BorderLayout.CENTER);
// Ensures JVM closes after frame(s) closed and
// all non-daemon threads are finished
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// See http://stackoverflow.com/a/7143398/418556 for demo.
f.setLocationByPlatform(true);
// ensures the frame is the minimum size it needs to be
// in order display the components within it
f.pack();
// should be done last, to avoid flickering, moving,
// resizing artifacts.
f.setVisible(true);