Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for displaying text in Java?

I'm completing a university assignment in java. It consists of some inputs, a block of text and a graph dependent on the inputs.

In my course I've been taught to display text using drawString directly onto a graphics object. Surely there is a better way than this! Is there a component/container that can be used to display uneditable text?

Should I be using drawString to output textual information or some other way?

like image 208
AnnanFay Avatar asked Apr 15 '11 18:04

AnnanFay


People also ask

How to display text in JTextArea in Java?

The following code creates and initializes the text area: textArea = new JTextArea(5, 20); JScrollPane scrollPane = new JScrollPane(textArea); textArea. setEditable(false); The two arguments to the JTextArea constructor are hints as to the number of rows and columns, respectively, that the text area should display.

What is the Java Swing?

Java Swing is a lightweight Java graphical user interface (GUI) widget toolkit that includes a rich set of widgets. It is part of the Java Foundation Classes (JFC) and includes several packages for developing rich desktop applications in Java.

How do I add text to a JFrame?

setText(""); And all you have to do is place the label in your layout, or whatever layout system you are using, and then just add it to the JFrame... Thanks for the quick response.


1 Answers

JLabel is probably what you're looking for.

like image 84
JB Nizet Avatar answered Oct 05 '22 21:10

JB Nizet