Everything runs fine but I dont see the text I set in my JTextArea.
Any ideas?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Mywindow {
public static void main(String[] args) {
CenteredFrame frame = new CenteredFrame();
GPanelWithText GPanel = new GPanelWithText();
frame.getContentPane().add(GPanel);
//frame.setContentPane(GPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
class CenteredFrame extends JFrame
{
public CenteredFrame()
{
//get screen dimensions
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
// center frame in screen
setSize(screenWidth / 2, screenHeight / 2);
setLocation(screenWidth / 4, screenHeight / 4);
// set frame icon and title
Image img = kit.getImage("icon.gif");
setIconImage(img);
setTitle("CenteredFrame");
}
}
class GPanelWithText extends JScrollPane {
public GPanelWithText () {
JTextArea text = new JTextArea("This is a test",5,30);
text.setLineWrap(true);
text.setWrapStyleWord(true);
text.setVisible(true);
this.setVerticalScrollBarPolicy
(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.setPreferredSize(new Dimension(250,250));
this.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("My
Panel"),
BorderFactory.createEmptyBorder
(5,5,5,5)),
this.getBorder()));
} //end constructor
} //ends GPanelWithText