Foros del Web » Programación para mayores de 30 ;) » Java »

jDialog. Que significa Frame owner???

Estas en el tema de jDialog. Que significa Frame owner??? en el foro de Java en Foros del Web. Hola. Quiero saber si me puden explicar como usar el frame owner que sale en el constructor de un JDialog. Recien me estoy iniciando y ...
  #1 (permalink)  
Antiguo 06/06/2009, 19:38
 
Fecha de Ingreso: marzo-2008
Mensajes: 99
Antigüedad: 16 años, 1 mes
Puntos: 1
jDialog. Que significa Frame owner???

Hola. Quiero saber si me puden explicar como usar el frame owner que sale en el constructor de un JDialog. Recien me estoy iniciando y estoy armando la interfaz grafica.

Cuando genero el JDialog me sale esto

public k(Frame owner) {
super(owner);
initialize();
}

y quiero saber como hago para utilizar el frame owner. Ya que por lo que lei este define la relacion padre e hijo, si no me equivoco.
Este JDialog lo llamo de un JInternalFrame. El cual es llamado de un JFrame.
Esto lo pregunto proque para hacerlo andar, puse el constructor vacio, pero no creo que este bien. no se si me explico.??
  #2 (permalink)  
Antiguo 07/06/2009, 04:13
(Desactivado)
 
Fecha de Ingreso: abril-2009
Mensajes: 113
Antigüedad: 15 años
Puntos: 1
Respuesta: jDialog. Que significa Frame owner???

El padre es el objeto que crea el JDialog.
El frame owner no lo puedes manejar como tal. Lo que si que puedes manejar es el padre del JDialog.

Siento no tener muchos conocimientos de teoria (yo tambien voy buceando como puedo) pero vamos.. lo que te digo. Intenta poner en frame owner el objeto que crea ese JDialog, para que sepa de quien depende ese JDialog. (tambien puedes probar con "this")

Un saludo
  #3 (permalink)  
Antiguo 07/06/2009, 05:35
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 6 meses
Puntos: 51
Respuesta: jDialog. Que significa Frame owner???

Del tutorial de Java:
Cita:
A Dialog window is an independent subwindow meant to carry temporary notice apart from the main Swing Application Window.... Every dialog is dependent on a Frame component. When that Frame is destroyed, so are its dependent Dialogs. When the frame is iconified, its dependent Dialogs also disappear from the screen. When the frame is deiconified, its dependent Dialogs return to the screen.
O sea, es una "sub-ventana" que es dependiente de otra, y su comportamiento por tanto, va en relación a la ventana de la que depende. Y quien es esa "otra" -> Pues la que le pasas en el constructor.

Si lees el API veras que si usas el constructor vacío, en realidad no estas creando un dialogo independiente, si no que se crea una ventana oculta para compartir ese tipo de diálogos.

S!
__________________
Para obtener respuestas, pregunta de forma inteligente o si no, pregunta lo que quieras que yo contestaré lo que me dé la gana.
  #4 (permalink)  
Antiguo 07/06/2009, 12:12
 
Fecha de Ingreso: marzo-2008
Mensajes: 99
Antigüedad: 16 años, 1 mes
Puntos: 1
Respuesta: jDialog. Que significa Frame owner???

Si, lo que yo ando buscando es que alguien me exlpique como usar el owner. Asi en vez de poner vacio el constructor, lo utilizo con el owner y me evito problemas mas adelnate.
  #5 (permalink)  
Antiguo 07/06/2009, 12:36
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 6 meses
Puntos: 51
Respuesta: jDialog. Que significa Frame owner???

¿Que quieres decir con "como usarlo"? Se supone que un dialogo lo muestras sobre una ventana, pues esa ventana es la que le tienes que pasar en el constructor. No hay más truco.

S!
__________________
Para obtener respuestas, pregunta de forma inteligente o si no, pregunta lo que quieras que yo contestaré lo que me dé la gana.
  #6 (permalink)  
Antiguo 07/06/2009, 15:24
(Desactivado)
 
Fecha de Ingreso: abril-2009
Mensajes: 113
Antigüedad: 15 años
Puntos: 1
Respuesta: jDialog. Que significa Frame owner???

Frame Owner es en castellano el objeto padre. No tienes que utilizar nada que se llame frame owner, ni manejarlo ni nada. Utiliza la ventana padre que ya la tienes creada.

Un saludo
  #7 (permalink)  
Antiguo 07/06/2009, 16:40
(Desactivado)
 
Fecha de Ingreso: abril-2009
Mensajes: 113
Antigüedad: 15 años
Puntos: 1
Respuesta: jDialog. Que significa Frame owner???

Intenta poner lo siguiente.

Cita:
JDialog dialogo = new JDialog( super.getFrame(),"Nombre ventana",true)
Te coge el frame del objeto padre y te hace el jDialog.

OTRA cosa. En principio a mí me compila y me reconoce perfectamente un jDialog que no tenga padre. No sé, será cosa de NetBeans 6.5. y de SUN y del lenguaje... no sé.
Referencia de los métodos de jDialog de SUN

Te debe compilar sin problemas si dejas en blanco los parametros del constructor. Ahora bien.. haria un dialogo "no modal". Si quieres un dialogo modal estas obligado a poner el "owner".

Un saludo

P.D. Oye, que ya te vale, ya te vale. Te he pedido tres veces el código. Al menos podrías haber puesto la línea del "new JDialog". Me voy a sacar la certificación, pero en vez de Java de "adivino Octavio Acebes"

Un saludo

Última edición por itubal; 07/06/2009 a las 16:51
  #8 (permalink)  
Antiguo 08/06/2009, 10:26
 
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;
}

}
  #9 (permalink)  
Antiguo 08/06/2009, 11:00
(Desactivado)
 
Fecha de Ingreso: abril-2009
Mensajes: 113
Antigüedad: 15 años
Puntos: 1
Respuesta: jDialog. Que significa Frame owner???

Ya.. bueno.. gracias por el código.
Pero la respuesta está dada. Supongo que ya lo habrás solucionado.
Una pista, el error esta, no tanto en la linea del JDialog si no en la siguiente. Despiste supertonto. Miralo bien y no te despistes.

Un saludo

Última edición por itubal; 08/06/2009 a las 11:18
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:21.