English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am trying to get a JTextArea to clear, or be set to blank, so I have a button that sets the area to " " (area.setText(" ");), but it doesn't do anything, and the text that's in the box will just stay there.

Also, I made two panels inside a frame using a GridLayout, and I want to layout components inside each of the panels, how do I do that, right now I have, what I guess is a flowlayout inside each panel.

2006-11-12 06:14:55 · 4 answers · asked by 123SP 1 in Computers & Internet Programming & Design

4 answers

Q1: Yes, all JTextComponent subclasses inherit the setText() method. Calling this method and passing null or an empty String has the effect of emptying the associated Document. The fact that yours doesn't work implies one of two possible problems: 1) the variable doesn't refer to the same JTextArea you are thinking of. Check to make sure you haven't called "new JTextArea()" any extra times or places. 2) or, for some reason, the JTextArea is not getting refreshed (graphics-wise). Try changing the size while running and see if that forces a refresh.

Otherwise, update this post with some of the relevant code and I will look at it.

Q2: If you want the components laid out using FlowLayout, just start adding your components to the JPanels. Otherwise, change the layout manager for each by creating a new layout instance and setting it on the JPanel, e.g.

upperPanel.setLayout(new BorderLayout());
bottomPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

2006-11-13 04:39:00 · answer #1 · answered by vincentgl 5 · 0 0

Yes, this is your problem: JPanel Option1 = new JPanel; Create it in your application constructor instead (or Main, or wherever you're creating all the other JPanels). Just set it to not visible initially. You also need to Add it to the JFrame, and I think therein lies your other problem. Buy and read _Head First Java_. Skip ahead to the chapter on Swing. It will tell you how to do everything you're attempting clearly and in a light-hearted fashion. You'll be better off reading it and doing what they say than trying to struggle along blindly. HTH

2016-03-28 03:22:09 · answer #2 · answered by ? 4 · 0 0

Try this one:A Java GUI Programmer's Primer ( Author(s):Fintan Culwin Publication date :April 1998 ISBN : 0-13-908849-0 Pages : 322 Publisher : Prentice Hall PTR )

2006-11-12 16:25:22 · answer #3 · answered by Anonymous · 0 0

Q1) the JTextarea does not use a set text function. it uses the document. goto the SDK docs page, and you will see you can set and edit the document object in the text area.

Q2) use myComponentReferance.SetLayout(SomeLayout);

good programming....

2006-11-12 06:29:52 · answer #4 · answered by origamix60 3 · 0 1

fedest.com, questions and answers