Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: John Cooper   on Jul 11 In Java Category.

  
Question Answered By: Heidi Larson   on Jul 11

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, BorderLayout.CENTER);
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 JTextArea {

public GPanelWithText () {

super("This is a test",5,30);
setLineWrap(true);
setWrapStyleWord(true);
this.setPreferredSize(new Dimension(250,250));
setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("My
Panel"),BorderFactory.createEmptyBorder(5,5,5,5)),this.getBorder()));

} //end constructor

} //ends GPanelWithText

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Why cant I see my JTextArea? Or get search suggestion and latest updates.


Tagged: