Reputation: 5427
In my program one user should fill a "Object" field with text of an arbitrary length. So I'd like to create a JTextArea with reasonable dimensions and with an associated JSrollPane in order to read all the inserted text, if it's very long. This is what I've done:
body.add(new JLabel("OGGETTO"), "1,2");
JTextArea oggetto = new JTextArea(5,20);
oggetto.setOpaque(true);
oggetto.setBackground(Color.cyan);
Border borderOgg = BorderFactory.createLineBorder(Color.BLACK);
oggetto.setBorder(BorderFactory.createCompoundBorder(borderOgg,
BorderFactory.createEmptyBorder(1, 1, 1, 1)));
oggetto.setLineWrap(true);
oggetto.setWrapStyleWord(true);
JScrollPane scroll1 = new JScrollPane(oggetto);
scroll1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
body.add(scroll1,"3,2");
body.add(oggetto, "2,2");
where body is a JPanel whose layout is TableLayout. But the scroll doesn't work even if it's showed. Why?
Upvotes: 1
Views: 882
Reputation: 46841
remove below line
body.add(oggetto, "2,2");
because JTextArea
is already added in JScrollPane
hence there is no need to add it again.
Upvotes: 2