Changing JTextArea to JScrollPane Causes it to not be visible
Posted
by
user1806716
on Stack Overflow
See other posts from Stack Overflow
or by user1806716
Published on 2012-11-07T16:17:58Z
Indexed on
2012/11/07
17:00 UTC
Read the original article
Hit count: 205
I am having an issue with JScrollPanes and JTextArea objects and getting them to work together.
If I just add a JTextArea to my JPanel, it works fine and shows up where I tell it to. However, if I change the contentPane.add(textArea) to contentPane.add(new JScrollPane(textArea)), the textArea is not longer visible and there is no sign of the textarea either.
Here is my code:
public docToolGUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 611, 487);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(253, 323, 86, 20);
contentPane.add(textField);
textField.setColumns(10);
JLabel lblEnterRootDirectory = new JLabel("Enter Root Directory");
lblEnterRootDirectory.setBounds(253, 293, 127, 20);
contentPane.add(lblEnterRootDirectory);
JButton btnGo = new JButton("Go");
btnGo.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
new ToolWorker().execute();
}
});
btnGo.setBounds(253, 361, 89, 23);
contentPane.add(btnGo);
textArea = new JTextArea();
textArea.setWrapStyleWord(true);
textArea.setEditable(false);
textArea.setBounds(25, 11, 560, 276);
contentPane.add(new JScrollPane(textArea));
}
© Stack Overflow or respective owner