Pergunta

This concerns JAVA programming. I have a confusing question that I can't seem to figure out despite searching all over the internet. I am somewhat of a newer programmer, so this may be a relatively stupid thing to ask.

Anyways, here is my question: I made a calculator GUI program (a simple one) that utilizes a JPanel with one text field, one JButton and one JTextArea.

My issue is that when I press the JButton and the calculated result is displayed in the JTextArea, if it's long enough in digits, everything above it in the JPanel gets shifted to the right. How do I fix this such that the content does not shift upon the button click/refresh of the panel?

Thanks, -Han

Foi útil?

Solução

From the sounds of it, you've added you textarea directly to your container without first adding it to a scrollpane.

The text area will grow as the content exceeds its current width/height.

Try adding your text area to a scroll pane and then add the scroll pane to your container...

textArea = new JTextArea(...)(
JScrollPane scrollPane = new JScrollPane(textArea);
add(scrollPane);

Take a look at How to use scroll panes and How to use text areas for more details

Outras dicas

Simple just add JTextArea in another JPanel with JScrollPane. Use appropriate Layout. Set JtextArea's lineWrap property to true.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top