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?
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.
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.
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.
JLabel is probably what you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With