I am a newbee so advise and help is always greatly appreciated.
Cannot seem to get my container contentPane to display the title.
My code:
class CreateStockCodeDetails extends JFrame implements ActionListener
{
OptraderSA parent;
OptraderGlobalParameters GV = new OptraderGlobalParameters();
private boolean DEBUG = true; //Set DEBUG = true for Debugging
JButton SAVE_BUTTON = new JButton("SAVE");
JButton CANCEL_BUTTON = new JButton("CANCEL");
Font MyFont = new Font("Helvetica",Font.BOLD,24);
JLabel PriceBidLabel = new JLabel(" Bid Price",JLabel.LEFT);
JLabel PriceAskLabel = new JLabel(" Ask Price",JLabel.LEFT);
JLabel PriceMidLabel = new JLabel(" Mid Price",JLabel.LEFT);
JLabel DividendLabel = new JLabel(" Dividend",JLabel.LEFT);
JTextField PriceBid = new JTextField(5);
JTextField PriceAsk = new JTextField(5);
JTextField PriceMid = new JTextField(5);
JTextField Dividend = new JTextField(5);
JTextField NewUnderlyingCode = new JTextField(10);
String NewCode;
public void CreateStockDetails(String StockCode)
{
super("Hallo All");
Container contentPane = getContentPane();
setSize(400,500);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
//Centre Screen To Right Of Mai开发者_如何转开发n
Dimension sd=Toolkit.getDefaultToolkit().getScreenSize();
super.setLocation(sd.width/2-100/2, sd.height/2-300/2);
Thanks
Kind Regards Stephen
If it is a JFrame
, Window
, JInternalFrame
, ect, just call
setTitle("Hallo");
Also, the call to super must be the first call in your constructor.You need to set the title to the JFrame and not the ContentPane
A container doesn't have a setTitle() method. Please read the API.
In addition to setting the title of the JFrame, you can add a "titled" border around the content pane:
JPanel content = (JPanel)getContentPane();
content.setBorder( ... );
Read the section from the Swing tutorial on How to Use Borders for an example of using a TitledBorder.
精彩评论