Reputation: 1
public class Main {
private static void createAndShowGUI() {
JFrame frame1 = new JFrame("FINAL YEAR PROJECT VER 1.0");
frame1.setSize(500,500);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout experimentLayout = new FlowLayout();
experimentLayout.setAlignment(FlowLayout.CENTER);
frame1.setLayout(experimentLayout);
JTextArea jtextarea = new JTextArea(200,200);
JScrollPane scrollingArea = new JScrollPane(jtextarea);
frame1.getContentPane().add(jtextarea);
frame1.getContentPane().add(scrollingArea, FlowLayout.CENTER);
jtextarea.setText("Welcome to Document-Query Similarity System Based On Weblogs");
frame1.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
I am trying to display text using the setText()
method on JTextarea
. However, the string does not display. What am I missing?
Upvotes: 0
Views: 1535
Reputation: 23639
It is there, just make the textarea much smaller. Something like:
JTextArea jtextarea = new JTextArea(20,20);
With it's current size you don't see the text. Part of the reason you can't scroll to the text is the incorrect way you are adding the textarea and the scroll bar. A better way to do that would be:
frame1.setLayout(new BorderLayout());
...
//delete the addition of the textarea to the frame, you already put it in the scroll pane.
frame1.getContentPane().add(scrollingArea, BorderLayout.CENTER);
Upvotes: 3
Reputation: 26809
Replace:
JTextArea jtextarea = new JTextArea();
instead of:
JTextArea jtextarea = new JTextArea(200, 200);
Documentation for your constructor said that arguments arent in pixels:
Constructs a new empty TextArea with the specified number of rows and columns. A default model is created, and the initial string is null.
Upvotes: 1