0

So I have created a JTextArea (in my case TextArea - to override append and setText methods that include line breaks), to visualise end user what is going on at what time.

I have:

  1. limited space
  2. Vision for the general look

I want to have that TextField "scrollable", but also I want the size to be whatever I setPrefferedSize to.

In first place, scrolling ability didn't work - this has been solved by removing the setPrefferedSize from the code. Just to see what would happen I tried doing setSize, which didn't help either.

Is it possible to combine those two functionalities? I position scrolling ability beyond the size, because I can just spam spaces, which doesn't sound like supported way to do it...

[...]
    TextArea interfaceArea = new TextArea();
    interfaceArea.setBorder(BorderFactory.createLoweredBevelBorder());
//  interfaceArea.setLineWrap(true);
//  interfaceArea.setPreferredSize(new Dimension(650, 70));
//  interfaceArea.setSize(new Dimension(650, 70));
    interfaceArea.setFont(FONT_BAGHDAD);
    interfaceArea.setText("PLACEHOLDER FOR LOGS\n");
    interfaceArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(interfaceArea); 
 
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    interfacePanel.add(scrollPane);
[...]

1 Answer 1

0

Providing int parameters for columns and rows in the JTextArea's constructor, solves this problem.

TextArea interfaceArea = new TextArea(5,55);

Not the answer you're looking for? Browse other questions tagged or ask your own question.