Assignment 4 supplement: JTextArea, JScrollPane, String.format(), UML
JTextArea with JScrollPane (for Bonus: Amortization Schedule)
It's difficult to use many labels for each line in your amortization schedule, so you can use a JTextArea instead. A JTextArea is your standard text box, but it doesn't come with scrolling. To make scrolling work, we put the JTextArea inside a JScrollPane, which will automatically resize based on your JTextArea's size.
JTextArea textArea = new JTextArea(200, 300); //sample row and col values, change this if needed
textArea.setLineWrap(true); //if the line is too long, wrap it to the next line
textArea.setEditable(false); //user should not be able to edit the text in the text box
JScrollPane scroll = new JScrollPane (textArea); //make a scroll pane around the text box
textArea.append("some text I want to append"); //use append to keep adding more lines to your amortization schedule
In previous assignments, you used System.out.printf() to format your strings.
Double someAmount = 0.123456789;
System.out.printf("This is the number with two decimals only: %.2f", someNumber); // Output: 0.12
If you are setting the text of some element, you can use String.format() instead:
someLabel.setText(String.format("This is the number with two decimals only: $%.2f", someNumber)); // Output: $0.12
UML diagram example