# MDI Application mit einen klein Dialog für Kind



## Miriam (19. Okt 2007)

ich möchte eine MDI Applikation erstellen wobei wenn man auf Neues Fenster klickt dass erst eine Fenster kommt wo man die Eigenschaft des Kindes-Fenster gibt (z.B. Name höhe und Breite) und beim drucken auf OK wird dann das Kind Fenster mit dem Eigenschaft generiert. 

es wäre nett wenn jemand mir eine Beispiel code generieren kann oder mir einen Buch empfehlen könntest.   :### 

mfg


----------



## Kim Stebel (19. Okt 2007)

Hast du es mal selbst probiert? Welche Probleme sind aufgetreten?


----------



## Miriam (22. Okt 2007)

Hallo Kim

ich babe schon ein MDI Application erstellt nur ich weiss nicht wie ich die Kommunikation zwischen mein Application und die Dialogfenster erstellen soll.
hier meine application

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;

@SuppressWarnings("serial")
class DesktopFrame extends JFrame implements ActionListener{
  private JDesktopPane desk;
  JButton opDialog = new JButton("neues Kind");
  Mydialog dialog;

  public DesktopFrame()
  {
    super("DesktopFrame");
    this.desk = new JDesktopPane();
   setContentPane(desk);
    add(opDialog);
    opDialog.setBounds(100, 100, 130, 50);
    opDialog.addActionListener(this);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    dialog = new Mydialog(this);
  }
  class ChildFrame extends JInternalFrame
  {
    public ChildFrame(String title)
    {
      super( title, true, true);
      setIconifiable(true);
      setMaximizable(true);
      setBackground(Color.lightGray);
    }
  }

  public void addChild(JInternalFrame child, int x, int y, int h, int w)
  {
    child.setLocation(x, y);
    child.setSize(w, h);
    child.setDefaultCloseOperation(
    JInternalFrame.DISPOSE_ON_CLOSE
    );
    desk.add(child);
    child.setVisible(true);
  }
  public void actionPerformed(ActionEvent e)
  {
     if (e.getSource().equals(opDialog))
     {

    	 addChild(new ChildFrame("xxxxx"), 10, 10,100, 150);
     }

  }
 }

public class TestMDI
{
  public static void main(String[] args)
  {
    //Desktop erzeugen
    DesktopFrame desktop = new DesktopFrame();
    desktop.setLocation(100, 100);
    desktop.setSize(800, 600);
    desktop.setVisible(true);

  }
}


----------



## Kim Stebel (22. Okt 2007)

also du willst statt "10,10,100,150" benutzerdefinierte Werte verwenden??


----------



## Guest (23. Okt 2007)

Hallo Kim
Genau das hätte ich gern. wobei einen Dialogfenster "Popup" kommt, wo man die Werte eingeben kann


----------



## Kim Stebel (23. Okt 2007)

poste mal den code für das dialogfenster


----------



## Miriam (23. Okt 2007)

hier ist dans dialogFenster

mport java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

class NeueFensterDialog extends JDialog implements ActionListener {
	JButton btnschl = new JButton("Schließen");
	JButton btnNeue = new JButton("neue Fenster");
	JTextField fensterNameField = new JTextField("", 20);
	JTextField xField = new JTextField("", 20);
	JTextField yField = new JTextField("", 20);
	JTextField breiteField = new JTextField("", 20);
	JTextField hoheField = new JTextField("", 20);

   public NeueFensterDialog(Frame owner, String title) {
       super(owner, title);

       setSize(380, 200);
       setResizable(false);
       getContentPane().setLayout(null);

       //Fenster name
       JLabel fensterNameLabel = new JLabel("Fenster Name");
       fensterNameLabel.setBounds(new Rectangle(20, 20, 100, 20));
       getContentPane().add(fensterNameLabel, null);

       fensterNameField.setBounds(new Rectangle(120, 20, 180, 20));
       getContentPane().add(fensterNameField, null);

       // X 
       JLabel xLabel = new JLabel("X Pos.:");
       xLabel.setBounds(new Rectangle(20, 50, 80, 20));
       getContentPane().add(xLabel, null);
       xField.setBounds(new Rectangle(120, 50, 60, 20));
       getContentPane().add(xField, null);
       // Y       
       JLabel yLabel = new JLabel("Y Pos.:");
       yLabel.setBounds(new Rectangle(200, 50, 80, 20));
       getContentPane().add(yLabel, null);
       yField.setBounds(new Rectangle(240, 50, 60, 20));
       getContentPane().add(yField, null);

       // breite 
       JLabel breiteLabel = new JLabel("Breite:");
       breiteLabel.setBounds(new Rectangle(20, 80, 80, 20));
       getContentPane().add(breiteLabel, null);
       breiteField.setBounds(new Rectangle(120, 80, 60, 20));
       getContentPane().add(breiteField, null);
       // Hohe
       JLabel hoheLabel = new JLabel("Hohe:");
       hoheLabel.setBounds(new Rectangle(200, 80, 80, 20));
       getContentPane().add(hoheLabel, null);
       hoheField.setBounds(new Rectangle(240, 80, 60, 20));
       getContentPane().add(hoheField, null);

       //Taste schliessen
       btnschl.setBounds(new Rectangle(50, 120, 120, 20));
       btnschl.addActionListener(this);
       getContentPane().add(btnschl, null);

       //Taste neue Fenster
       btnNeue.setBounds(new Rectangle(200, 120, 120, 20));
       btnNeue.addActionListener(this);
       getContentPane().add(btnNeue, null);


   }

   public void actionPerformed(ActionEvent e) {
	     if (e.getSource().equals(btnschl))
	     {
             setVisible(false);
	     }
	     if (e.getSource().equals(btnNeue))
	     {
	//    	 addChild(new ChildFrame("xxxxx"), 10, 10,100, 150);
	     }
   }
}


----------



## Kim Stebel (23. Okt 2007)

try
{
addChild(new ChildFrame(fensterNameField.getText()), Integer.parseInt(xField.getText()), Integer.parseInt(yField.getText()), Integer.parseInt(breiteField.getText()), Interger.parseInt(hoheField.getText()));
}
catch (NumberFormatException nfe)
{
  //Fehlermeldung...
}


----------



## Miriam (23. Okt 2007)

addChild(new *ChildFrame* wird nicht erkannt und er fordert eine Class


----------



## Kim Stebel (23. Okt 2007)

tu die ChildFrame-Klasse in ne eigene datei und mach sie public


----------



## Miriam (23. Okt 2007)

da ist genau meine Probleme
wenn ich dass in eigne Class mache kennt er nicht mehr das Hauptfenster. wenn ich das as Argument gebe beim aufruf kann ich nicht mehr auf die Hauptfenster zugreifen da über this nur auf meinen Dialogfenster komme


----------



## Kim Stebel (23. Okt 2007)

mach es einfach und sag mir die fehlermeldung.


----------



## Miriam (23. Okt 2007)

Fehlermeldung addChild nimmt nur JInternalFrame abhilfe soll ich eine methode
private void addChild(JInternalFrame frame, int i, int j, int k, int l) {
	// TODO Auto-generated method stub

}
 definieren diese Methode gibt aber schon als public.

dazu kennt er den JDesktopPane desk nicht mehr


----------



## Kim Stebel (23. Okt 2007)

werd nicht schlau aus dem was du da schreibst. kannst du nicht einfach die fehlermeldungen kopieren? und zwar alle? oder alternativ exportier das ganze als jar und schick mir das


----------



## Miriam (23. Okt 2007)

habe probiert deine E-mail funktionniert nicht


----------



## *Hendrik (23. Okt 2007)

Mal eine andere Möglichkeit: Im Konstruktor des Child-Fensters wird zunächst ein Einstellungsfenster über JOptionPane aufgerufen:


```
import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class MyMDI extends javax.swing.JFrame implements java.awt.event.ActionListener {
    
    public MyMDI() {
        initComponents();
    }
                  
    private void initComponents() {
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test MDI");
        getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER);

        jMenu1.setText("Menu");
        jMenuItem1.setText("Fenster aufrufen");
        jMenuItem1.addActionListener(this);

        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-887)/2, (screenSize.height-655)/2, 887, 655);
    }

    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == jMenuItem1) {
            MyMDI.this.jMenuItem1ActionPerformed(evt);
        }
    }                        

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        MyInternalFrame iFrame = new MyInternalFrame(jDesktopPane1);
        jDesktopPane1.add(iFrame);      
    }                                          

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MyMDI().setVisible(true);
            }
        });
    }
                
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;                 
    
}

class MyInternalFrame extends javax.swing.JInternalFrame {

    public MyInternalFrame(JDesktopPane desktop) {
                
        initComponents(); 
        
        JTextField titel = new JTextField("Titel");
        JTextField posX= new JTextField("10");
        JTextField posY = new JTextField("10");
        JTextField width = new JTextField("400");
        JTextField height = new JTextField("300");        
        
        Object[] msg = {"Titel:", titel, "Pos X:", posX, "Pos Y:", posY, "Länge:", width, "Höhe:", height};        
        JOptionPane op = new JOptionPane();

        if(op.showInternalConfirmDialog(desktop,msg,"Fensterangaben",JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){
            int x = Integer.parseInt(posX.getText());
            int y = Integer.parseInt(posY.getText());
            int newWidth = Integer.parseInt(width.getText());
            int newHeight = Integer.parseInt(height.getText());
            
            this.setTitle(titel.getText());
            this.setBounds(x,y,newWidth,newHeight);
            
            setVisible(true);            
            
        } else {
            dispose();                  
        }
                                            
    }
    
    private void initComponents() {

        getContentPane().setLayout(null);

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-404)/2, (screenSize.height-313)/2, 404, 313);
    
    }
}
```
(Die parseInt-Anweisungen sollten noch auf korrekte Eingaben geprüft werden.)

Ohne JOptionPane würde ich 2 JInternalFrames nehmen. D.h. Dein Einstellungsfenster für Titel, Größe usw. und Dein eigentliches Fenster. Beim Aufruf über des Menüs würde ich das Einstellungsfenster aufrufen und eine Instanz des JDesktopPanes übergeben. Nachdem die Einstellungen vorgenommen wurden, kannst Du dann Dein eigentliches Fenster erstellen und den DesktopPane hinzufügen. (Vllt. mach ich mal ein Codebeispiel).


----------



## Miriam (23. Okt 2007)

ich danke dir das ist sehr nett :toll:


----------



## *Hendrik (23. Okt 2007)

Die 2. Version. 
Gefällt mir wesentlich besser, da der Einstellungsdialog frei programmiert werden kann. (Der 2. Menüpunkt ruft die neue Version mit der Klasse CustomizeInternalFrame auf.)


```
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class MyMDI extends javax.swing.JFrame implements java.awt.event.ActionListener {
    
    public MyMDI() {
        initComponents();
    }
    
    // <editor-fold defaultstate="collapsed" desc=" Erzeugter Quelltext ">                          
    private void initComponents() {
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test MDI");
        getContentPane().add(jDesktopPane1, java.awt.BorderLayout.CENTER);

        jMenu1.setText("Menu");
        jMenuItem1.setText("Fenster aufrufen");
        jMenuItem1.addActionListener(this);

        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Fenster aufrufen 2");
        jMenuItem2.addActionListener(this);

        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-887)/2, (screenSize.height-655)/2, 887, 655);
    }

    // Quelltext zum Weiterleiten von Ereignissen von Komponenten zu Behandlungsmethoden.

    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == jMenuItem1) {
            MyMDI.this.jMenuItem1ActionPerformed(evt);
        }
        else if (evt.getSource() == jMenuItem2) {
            MyMDI.this.jMenuItem2ActionPerformed(evt);
        }
    }// </editor-fold>                        

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        CustomizeInternalFrame iFrame = new CustomizeInternalFrame(jDesktopPane1);
        jDesktopPane1.add(iFrame);
        iFrame.setVisible(true);
    }                                          

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        MyInternalFrame iFrame = new MyInternalFrame(jDesktopPane1);
        jDesktopPane1.add(iFrame);      
    }                                          

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MyMDI().setVisible(true);
            }
        });
    }
    
    // Variablendeklaration - nicht modifizieren                     
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    // Ende der Variablendeklaration                   
    
}

class MyInternalFrame extends javax.swing.JInternalFrame {
    
    /** Creates new form MyInternalFrame */
    public MyInternalFrame(JDesktopPane desktop) {
                
        initComponents(); 
        
        JTextField titel = new JTextField("Titel");
        JTextField posX= new JTextField("10");
        JTextField posY = new JTextField("10");
        JTextField width = new JTextField("400");
        JTextField height = new JTextField("300");        
        
        Object[] msg = {"Titel:", titel, "Pos X:", posX, "Pos Y:", posY, "Länge:", width, "Höhe:", height};        
        JOptionPane op = new JOptionPane();

        if(op.showInternalConfirmDialog(desktop,msg,"Fensterangaben",JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION){
            int x = Integer.parseInt(posX.getText());
            int y = Integer.parseInt(posY.getText());
            int newWidth = Integer.parseInt(width.getText());
            int newHeight = Integer.parseInt(height.getText());
            
            this.setTitle(titel.getText());
            this.setBounds(x,y,newWidth,newHeight);
            
            setVisible(true);            
            
        } else {
            dispose();                  
        }
                                            
    }
    
    private void initComponents() {

        getContentPane().setLayout(null);

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-404)/2, (screenSize.height-313)/2, 404, 313);
    
    }
}

class CustomizeInternalFrame extends javax.swing.JInternalFrame implements java.awt.event.ActionListener {
    
    private JDesktopPane desktop;
    
    public CustomizeInternalFrame(JDesktopPane desktop) {
        this.desktop = desktop;
        initComponents();
    }
                       
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tfTitel = new javax.swing.JTextField();
        tfPosX = new javax.swing.JTextField();
        tfPosY = new javax.swing.JTextField();
        tfWidth = new javax.swing.JTextField();
        tfHeight = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setClosable(true);
        setTitle("Einstellungen");
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabel1.setText("Titel:");
        jLabel1.setPreferredSize(new java.awt.Dimension(150, 20));

        jLabel2.setText("Position X:");
        jLabel2.setPreferredSize(new java.awt.Dimension(150, 20));

        jLabel3.setText("Position Y:");
        jLabel3.setPreferredSize(new java.awt.Dimension(150, 20));

        jLabel4.setText("L\u00e4nge:");
        jLabel4.setPreferredSize(new java.awt.Dimension(150, 20));

        jLabel5.setText("H\u00f6he:");
        jLabel5.setPreferredSize(new java.awt.Dimension(150, 20));

        tfTitel.setText("Titel");

        tfPosX.setColumns(5);
        tfPosX.setText("10");

        tfPosY.setColumns(5);
        tfPosY.setText("10");

        tfWidth.setColumns(5);
        tfWidth.setText("400");

        tfHeight.setColumns(5);
        tfHeight.setText("200");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfTitel, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfPosX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfPosY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTitel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPosX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPosY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setText("Ok");
        jButton1.addActionListener(this);

        jButton2.setText("Abbrechen");
        jButton2.addActionListener(this);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        setBounds(0, 0, 454, 236);
    }

    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == jButton1) {
            CustomizeInternalFrame.this.jButton1ActionPerformed(evt);
        }
        else if (evt.getSource() == jButton2) {
            CustomizeInternalFrame.this.jButton2ActionPerformed(evt);
        }
    }                     

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        dispose();
    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JInternalFrame iFrame = new JInternalFrame();   //Das ist dann Dein eigentlicher JInternalFrame
        
        int x = Integer.parseInt(tfPosX.getText());
        int y = Integer.parseInt(tfPosY.getText());
        int newWidth = Integer.parseInt(tfWidth.getText());
        int newHeight = Integer.parseInt(tfHeight.getText());
        
        iFrame.setTitle(tfTitel.getText());
        iFrame.setBounds(x,y,newWidth,newHeight);        
        iFrame.setClosable(true);
        iFrame.setVisible(true);
        desktop.add(iFrame);    
        
        this.dispose();

    }                                        
                           
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField tfHeight;
    private javax.swing.JTextField tfPosX;
    private javax.swing.JTextField tfPosY;
    private javax.swing.JTextField tfTitel;
    private javax.swing.JTextField tfWidth;
```


----------



## *Hendrik (23. Okt 2007)

Im Grunde brauchst Du noch nicht mal jDesktopPane1 an den Konstruktor übergeben. Genausogut kannst Du in der Methode jButton1ActionPerformed(..)

```
((JDesktopPane)this.getParent()).add(iFrame);
```
anstatt

```
desktop.add(iFrame);
```

verwenden.


----------



## Miriam (23. Okt 2007)

erstaunlich wie du schnell progrmmieren kann
deine 2te Version funktionniert bei mir aber nicht du hast di Varable unten deklariert und javax.swing.GroupLayout wird nicht erkannt


----------



## *Hendrik (23. Okt 2007)

Ich erstelle es ja nur schnell mal mit NetBeans. 

Ja, ich habe unten eine Klammer } vergessen, wie Du wahrscheinlich gemerkt hast. NetBeans deklariert die Variablen immer unten. Dies ist aber egal und funktioniert. GroupLayout gibt es erst ab JRE 1.6, also wenn Du nicht diese Version hast, wird es nicht funktionieren.

Im Grunde ist ja nur Folgendes entscheidend:

1. Du rufst aus Deinem Hauptfenster den Einstellungsdialog auf.
2. In dem Einstellungsdialog initialisierst Du Deinen JInternalFrame und passt ihn an.
3. Du fügst den JInternalFrame dem DesktopPane hinzu und schließt Deinen Einstellungsdialog.

Also das hier:


```
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JInternalFrame iFrame = new JInternalFrame();   //Das ist dann Dein eigentlicher JInternalFrame
        
        int x = Integer.parseInt(tfPosX.getText());
        int y = Integer.parseInt(tfPosY.getText());
        int newWidth = Integer.parseInt(tfWidth.getText());
        int newHeight = Integer.parseInt(tfHeight.getText());
        
        iFrame.setTitle(tfTitel.getText());
        iFrame.setBounds(x,y,newWidth,newHeight);        
        iFrame.setClosable(true);
        iFrame.setVisible(true);
        ((JDesktopPane)this.getParent()).add(iFrame);    
        
        this.dispose();

    }
```

D.h. wie Du Deinen Einstellungsdialog aufbaust - mit GroupLayout oder ohne - liegt an Dir.

EDIT: Auch hier mußt Du natürlich wieder dafür Sorge tragen, dass in den Textfeldern das richtige drinsteht bzw. bei parstInt() aufpassen.


----------



## Miriam (23. Okt 2007)

warscheinlich benutzt du java6 ich benutze java 5 und javax.swing.GroupLayout fehlt


----------



## Miriam (23. Okt 2007)

fehler Meldung javax.swing.LayoutStyle cannot be resolved ich benutze eclipse


----------



## Miriam (23. Okt 2007)

Fehlermeldung wenn ich auf den Fenster aufrufen 2


Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: 
	The constructor GroupLayout(JPanel) is undefined
	The method setLayout(LayoutManager) in the type Container is not applicable for the arguments (GroupLayout)
	javax.swing.GroupLayout.Alignment cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.Alignment cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.Alignment cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.Alignment cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.Alignment cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.Alignment cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.Alignment cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.LayoutStyle cannot be resolved
	javax.swing.GroupLayout.Alignment cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	The constructor GroupLayout(Container) is undefined
	The method setLayout(LayoutManager) in the type Container is not applicable for the arguments (GroupLayout)
	javax.swing.GroupLayout.Alignment cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.Alignment cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.LayoutStyle cannot be resolved
	The method linkSize(int, Component[]) is undefined for the type GroupLayout
	javax.swing.GroupLayout.Alignment cannot be resolved
	The method createSequentialGroup() is undefined for the type GroupLayout
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved
	javax.swing.GroupLayout.DEFAULT_SIZE cannot be resolved
	javax.swing.GroupLayout.PREFERRED_SIZE cannot be resolved

	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.AbstractButton.doClick(Unknown Source)
	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)


----------



## *Hendrik (23. Okt 2007)

Ja, siehe mein vorheriger Post.

Ohne Layout-Manager (nur mal zum Testen). Ich habe die Components nicht sauber gesetzt.


```
class CustomizeInternalFrame extends javax.swing.JInternalFrame implements java.awt.event.ActionListener {
    
    private JDesktopPane desktop;
    
    public CustomizeInternalFrame(JDesktopPane desktop) {
        this.desktop = desktop;
        initComponents();
    }
                      
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tfTitel = new javax.swing.JTextField();
        tfPosX = new javax.swing.JTextField();
        tfPosY = new javax.swing.JTextField();
        tfWidth = new javax.swing.JTextField();
        tfHeight = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        getContentPane().setLayout(null);

        setClosable(true);
        setTitle("Einstellungen");
        jPanel1.setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jLabel1.setText("Titel:");
        jLabel1.setPreferredSize(new java.awt.Dimension(150, 20));
        jPanel1.add(jLabel1);
        jLabel1.setBounds(10, 10, 150, 20);

        jLabel2.setText("Position X:");
        jLabel2.setPreferredSize(new java.awt.Dimension(150, 20));
        jPanel1.add(jLabel2);
        jLabel2.setBounds(10, 35, 150, 20);

        jLabel3.setText("Position Y:");
        jLabel3.setPreferredSize(new java.awt.Dimension(150, 20));
        jPanel1.add(jLabel3);
        jLabel3.setBounds(10, 60, 150, 20);

        jLabel4.setText("L\u00e4nge:");
        jLabel4.setPreferredSize(new java.awt.Dimension(150, 20));
        jPanel1.add(jLabel4);
        jLabel4.setBounds(10, 85, 150, 20);

        jLabel5.setText("H\u00f6he:");
        jLabel5.setPreferredSize(new java.awt.Dimension(150, 20));
        jPanel1.add(jLabel5);
        jLabel5.setBounds(10, 115, 150, 20);

        tfTitel.setText("Titel");
        jPanel1.add(tfTitel);
        tfTitel.setBounds(180, 15, 210, 20);

        tfPosX.setColumns(5);
        tfPosX.setText("10");
        jPanel1.add(tfPosX);
        tfPosX.setBounds(180, 40, 46, 20);

        tfPosY.setColumns(5);
        tfPosY.setText("10");
        jPanel1.add(tfPosY);
        tfPosY.setBounds(180, 65, 46, 20);

        tfWidth.setColumns(5);
        tfWidth.setText("400");
        jPanel1.add(tfWidth);
        tfWidth.setBounds(180, 90, 46, 20);

        tfHeight.setColumns(5);
        tfHeight.setText("200");
        jPanel1.add(tfHeight);
        tfHeight.setBounds(180, 115, 46, 20);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(10, 10, 424, 150);

        jButton1.setText("Ok");
        jButton1.addActionListener(this);

        getContentPane().add(jButton1);
        jButton1.setBounds(10, 165, 75, 23);

        jButton2.setText("Abbrechen");
        jButton2.addActionListener(this);

        getContentPane().add(jButton2);
        jButton2.setBounds(90, 165, 85, 23);

        setBounds(0, 0, 453, 234);
    }

    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == jButton1) {
            CustomizeInternalFrame.this.jButton1ActionPerformed(evt);
        }
        else if (evt.getSource() == jButton2) {
            CustomizeInternalFrame.this.jButton2ActionPerformed(evt);
        }
    }
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        dispose();
    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JInternalFrame iFrame = new JInternalFrame();   //Das ist dann Dein eigentlicher JInternalFrame
        
        int x = Integer.parseInt(tfPosX.getText());
        int y = Integer.parseInt(tfPosY.getText());
        int newWidth = Integer.parseInt(tfWidth.getText());
        int newHeight = Integer.parseInt(tfHeight.getText());
        
        iFrame.setTitle(tfTitel.getText());
        iFrame.setBounds(x,y,newWidth,newHeight);        
        iFrame.setClosable(true);
        iFrame.setVisible(true);
        ((JDesktopPane)this.getParent()).add(iFrame);    
        
        this.dispose();

    }                                        
                  
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField tfHeight;
    private javax.swing.JTextField tfPosX;
    private javax.swing.JTextField tfPosY;
    private javax.swing.JTextField tfTitel;
    private javax.swing.JTextField tfWidth;               
    
}
```


----------



## *Hendrik (23. Okt 2007)

GroupLayout gibts natürlich auch als jar zum Einbinden - z.B. hier: Link


----------



## Miriam (23. Okt 2007)

danke es funktionniert aber ohne javax.swing.GroupLayout 
mit dem jar file hat auch nicht funktionniert fehlermeldung javax.swing.GroupLayout () nmmt keine argument

vielleicht kennst du mir eine paar Bücher mit NetBeans empfählen


----------



## *Hendrik (24. Okt 2007)

Ein Buch kann ich Dir nicht empfehlen, aber auf der NetBeans-Seite gibt es einige Tutorials.


----------



## Miriam (25. Okt 2007)

Ich habe schon netbean installiert und mit dem Tutorial probiert aber was mich immer Probleme aufbereitet ist das  Zusammenspiel der Komponenten in Gesamt-Application. wie z.B. ein Jtree, JPopupMenu.
Danke Du hast mir schon sehr geholfen. ich habe aber noch sehr viel zu lernen.


----------

