I don't know where the problem is, when the sample code is run alone and from scratch, the scrollbars are displayed correctly, but when we try to add them to a task area in the middle of a prepared frame, the text area disappears. The last solution I tried was this:
createAndShowGUI() {
//
JTextArea textArea = new JTextArea(20, 20);
JScrollPane scrollableTextArea = new JScrollPane(textArea);
scrollableTextArea.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
frame.getContentPane().add(scrollableTextArea)
//}
and for run it:
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
and had the same problem, Can Anybody Help?
Edit: I have to correct the question
In a good example, I would use this Line:
frame.getContentPane().setLayout(new FlowLayout());
And in bad usage, I used this line:
frame.getContentPane().setLayout(null); //"null" cannot be replaced because the frame and its objects are moved
Is there a layout that does not move the previous objects of the frame and shows the scroll bar correctly?