Home arrow static arrow Java Programming [Archive] - parents clientarea shows up in child
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - parents clientarea shows up in child
This topic has 1 reply on 1 page.

Posts:60
Registered: 3/30/04
parents clientarea shows up in child  
Jul 3, 2004 1:12 AM



 

I�m writing a aplication which shows a dialoagbox. the problem is that the clientarea of the dialog box is filled with the data from the parent boix as wel as controls i myself added. What can be the cause?

websphere.java

package websphere; import javax.swing.UIManager;import java.awt.*; import java.util.*;import java.io.*;import java.lang.*;import java.net.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ public class WebSphere {  boolean packFrame = false//Construct the application  public WebSphere() {    Frame1 frame = new Frame1();    //Validate frames that have preset sizes    //Pack frames that have useful preferred size info, e.g. from their layout    if (packFrame) {      frame.pack();    }    else {      frame.validate();    }    //Center the window    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();    Dimension frameSize = frame.getSize();    if (frameSize.height > screenSize.height) {      frameSize.height = screenSize.height;    }    if (frameSize.width > screenSize.width) {      frameSize.width = screenSize.width;    }    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);    frame.setVisible(true);     DGetProject dgp = new DGetProject();    dgp.setVisible(true);     try {      URL u = new URL("81.59.71.241");       ArrayList lines = new ArrayList();      BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));      String line;      while ((line = in.readLine()) != null) {        lines.add(line);      }    } catch (Exception e) {}  }   //Main method  public static void main(String[] args) {    try {      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());    }    catch(Exception e) {      e.printStackTrace();    }    new WebSphere();  }}


Frame1.java
package websphere; import java.awt.*;import java.awt.event.*;import javax.swing.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ public class Frame1 extends JFrame {  JPanel contentPane;  JMenuBar jMenuBar1 = new JMenuBar();  JMenu jMenuFile = new JMenu();  JMenuItem jMenuFileExit = new JMenuItem();  JMenu jMenuHelp = new JMenu();  JMenuItem jMenuHelpAbout = new JMenuItem();  JTree jTree = new JTree1();  JToolBar jToolBar = new JToolBar();  JButton jButton1 = new JButton();  JButton jButton2 = new JButton();  JButton jButton3 = new JButton();  ImageIcon image1;  ImageIcon image2;  ImageIcon image3;  JLabel statusBar = new JLabel();  BorderLayout borderLayout1 = new BorderLayout();   //Construct the frame  public Frame1() {    enableEvents(AWTEvent.WINDOW_EVENT_MASK);    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }   //Component initialization  private void jbInit() throws Exception  {    image1 = new ImageIcon(websphere.Frame1.class.getResource("openFile.png"));    image2 = new ImageIcon(websphere.Frame1.class.getResource("closeFile.png"));    image3 = new ImageIcon(websphere.Frame1.class.getResource("help.png"));    contentPane = (JPanel) this.getContentPane();    contentPane.setLayout(borderLayout1);    this.setSize(new Dimension(400, 300));    this.setTitle("Frame Title");    statusBar.setText(" ");    jMenuFile.setText("File");    jMenuFileExit.setText("Exit");    jMenuFileExit.addActionListener(new Frame1_jMenuFileExit_ActionAdapter(this));    jMenuHelp.setText("Help");    jMenuHelpAbout.setText("About");    jMenuHelpAbout.addActionListener(new Frame1_jMenuHelpAbout_ActionAdapter(this));    jButton1.setIcon(image1);    jButton1.setToolTipText("Open File");    jButton2.setIcon(image2);    jButton2.setToolTipText("Close File");    jButton3.setIcon(image3);    jButton3.setToolTipText("Help");    jToolBar.add(jButton1);    jToolBar.add(jButton2);    jToolBar.add(jButton3);    jMenuFile.add(jMenuFileExit);    jMenuHelp.add(jMenuHelpAbout);    jMenuBar1.add(jMenuFile);    jMenuBar1.add(jMenuHelp);    this.setJMenuBar(jMenuBar1);    contentPane.add(jToolBar, BorderLayout.NORTH);    contentPane.add(statusBar, BorderLayout.SOUTH);    contentPane.add(jTree, BorderLayout.CENTER);  }   //File | Exit action performed  public void jMenuFileExit_actionPerformed(ActionEvent e) {    System.exit(0);  }   //Help | About action performed  public void jMenuHelpAbout_actionPerformed(ActionEvent e) {    Frame1_AboutBox dlg = new Frame1_AboutBox(this);    Dimension dlgSize = dlg.getPreferredSize();    Dimension frmSize = getSize();    Point loc = getLocation();    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);    dlg.setModal(true);    dlg.pack();    dlg.show();  }   //Overridden so we can exit when window is closed  protected void processWindowEvent(WindowEvent e) {    super.processWindowEvent(e);    if (e.getID() == WindowEvent.WINDOW_CLOSING) {      jMenuFileExit_actionPerformed(null);    }  }} class Frame1_jMenuFileExit_ActionAdapter implements ActionListener {  Frame1 adaptee;   Frame1_jMenuFileExit_ActionAdapter(Frame1 adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jMenuFileExit_actionPerformed(e);  }} class Frame1_jMenuHelpAbout_ActionAdapter implements ActionListener {  Frame1 adaptee;   Frame1_jMenuHelpAbout_ActionAdapter(Frame1 adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jMenuHelpAbout_actionPerformed(e);  }} class JTree1 extends JTree { }


DGetProject:
package websphere; import java.awt.*;import javax.swing.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ public class DGetProject extends JDialog {  JLabel jLabel1 = new JLabel();  JTextField jTextField1 = new JTextField();   public DGetProject(Frame frame, String title, boolean modal) {    super(frame, title, modal);    try {      jbInit();    }    catch(Exception ex) {      ex.printStackTrace();    }  }   public DGetProject() {    this(null, "", true);  }   private void jbInit() throws Exception {    jLabel1.setText("Project Name : ");    jTextField1.setText("");     Container pane = this.getRootPane();    SpringLayout lo = new SpringLayout();    pane.setLayout(lo);    pane.setSize(200, 150);     pane.add(jLabel1);    pane.add(jTextField1);     lo.putConstraint(SpringLayout.WEST, jLabel1,                     5,                     SpringLayout.WEST, pane);    lo.putConstraint(SpringLayout.NORTH, jLabel1,                     5,                     SpringLayout.NORTH, pane);    lo.putConstraint(SpringLayout.WEST, jTextField1,                         5,                         SpringLayout.EAST, jLabel1);    lo.putConstraint(SpringLayout.NORTH, jTextField1,                         5,                         SpringLayout.NORTH, pane);   }}


I have a main window Frame1 which initializes DGetProject. The problem is that beside the controles i wnt there i also get the out put of Frame1 in my dialog...
Who can help?

gr. Razorblade
 

Posts:2,384
Registered: 3/16/01
Re: parents clientarea shows up in child  
Jul 3, 2004 3:40 AM (reply 1 of 1)



 
Use the content pane not the root pane (see JDialog api). And call JDialog methods on the class (which is a JDialog by virtue of extension) not on the content pane. This works okay now.
    private void jbInit() throws Exception {        jLabel1.setText("Project Name : ");        jTextField1.setText("hello world");         Container pane = this.getContentPane();        SpringLayout lo = new SpringLayout();        pane.setLayout(lo);        pane.add(jLabel1);        pane.add(jTextField1);        setSize(200, 150);        setLocation(200,200);         lo.putConstraint(SpringLayout.WEST, jLabel1,                         5,                         SpringLayout.WEST, pane);        lo.putConstraint(SpringLayout.NORTH, jLabel1,                         5,                         SpringLayout.NORTH, pane);        lo.putConstraint(SpringLayout.WEST, jTextField1,                         5,                         SpringLayout.EAST, jLabel1);        lo.putConstraint(SpringLayout.NORTH, jTextField1,                         5,                         SpringLayout.NORTH, pane);    }
 
This topic has 1 reply on 1 page.