Ver Mensaje Individual
  #8 (permalink)  
Antiguo 08/06/2009, 10:26
lordphoenixs
 
Fecha de Ingreso: marzo-2008
Mensajes: 99
Antigüedad: 16 años, 1 mes
Puntos: 1
Respuesta: jDialog. Que significa Frame owner???

Les publico el codigo de forma reducida de lo que yo hago.

el codigo del programa principal
Cita:
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JDesktopPane;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class Principal extends JFrame {

private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JDesktopPane jDesktopPane = null;
private JMenuBar jJMenuBar = null;
private JMenu jMenu = null;
private JMenuItem jMenuItem = null;
private JInternalFrame iframe = null;

/**
* This method initializes jDesktopPane
*
* @return javax.swing.JDesktopPane
*/
private JDesktopPane getJDesktopPane() {
if (jDesktopPane == null) {
jDesktopPane = new JDesktopPane();
}
return jDesktopPane;
}

/**
* This method initializes jJMenuBar
*
* @return javax.swing.JMenuBar
*/
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getJMenu());
}
return jJMenuBar;
}

/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getJMenu() {
if (jMenu == null) {
jMenu = new JMenu();
jMenu.setText("Usar");
jMenu.add(getJMenuItem());
}
return jMenu;
}

/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem() {
if (jMenuItem == null) {
jMenuItem = new JMenuItem();
jMenuItem.setText("Ventana");
jMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
llamar();
}
});
}
return jMenuItem;
}

private void llamar(){
iframe = new JInternalFrame("Prueba",false,true,true,true);
Ventanas vent = new Ventanas();
iframe.add(vent);
iframe.pack();
iframe.setVisible(true);

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Principal thisClass = new Principal();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);
thisClass.setVisible(true);
}
});
}

/**
* This is the default constructor
*/
public Principal() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setJMenuBar(getJJMenuBar());
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJDesktopPane(), BorderLayout.CENTER);
}
return jContentPane;
}

}
El codigo del panel del InternalFrame
Cita:
import java.awt.GridBagLayout;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.Color;
import java.awt.BorderLayout;

public class Ventanas extends JPanel {

private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JTextField jTextField = null;
private JComboBox jComboBox = null;
private JPanel jPanel = null;
private JButton jButton = null;
private JButton jButton1 = null;
private JDialog iDialog = null;

/**
* This is the default constructor
*/
public Ventanas() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setLayout(new BorderLayout());
this.add(getJContentPane(), BorderLayout.NORTH);
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.gridwidth = 3;
gridBagConstraints11.gridy = 2;
gridBagConstraints11.gridx = 0;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.fill = GridBagConstraints.VERTICAL;
gridBagConstraints2.gridy = 1;
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.gridx = 1;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.fill = GridBagConstraints.VERTICAL;
gridBagConstraints1.gridy = 0;
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.gridx = 1;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
jLabel = new JLabel();
jLabel.setText("JLabel");
jContentPane = new JPanel();
jContentPane.setLayout(new GridBagLayout());
jContentPane.add(jLabel, gridBagConstraints);
jContentPane.add(getJTextField(), gridBagConstraints1);
jContentPane.add(getJComboBox(), gridBagConstraints2);
jContentPane.add(getJPanel(), gridBagConstraints11);
}
return jContentPane;
}

/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setColumns(10);
}
return jTextField;
}

/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox(new String[]{"Hola"});
}
return jComboBox;
}

/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(new FlowLayout());
jPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createBevelBorder(BevelBorder.RAISED ), "Boton", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
jPanel.add(getJButton(), null);
jPanel.add(getJButton1(), null);
}
return jPanel;
}

/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Prueba");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
llamado();
}
});
}
return jButton;
}

private void llamado (){
iDialog = new JDialog();-->Aca esta el dialog pelado como lo llamo yo.
iDialog.setModal(true);
Sep vento = new Sep();
iDialog.add(vento);
iDialog.pack();
iDialog.setVisible(true);
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("Cancelar");
}
return jButton1;
}

}
por ultimo el codigo del panel del JDialog

Cita:
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.GridBagConstraints;

public class Sep extends JPanel {

private static final long serialVersionUID = 1L;
private JButton jButton = null;
private JButton jButton1 = null;

/**
* This is the default constructor
*/
public Sep() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 1;
gridBagConstraints1.gridy = 0;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(getJButton(), gridBagConstraints);
this.add(getJButton1(), gridBagConstraints1);
}

/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("OK");
}
return jButton;
}

/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("Mal");
}
return jButton1;
}

}