Buscar
Social
Ofertas laborales ES

Foro sobre Java SE > Focus a un internal jframe.

Buenas.
Quiero que al abrir un internal frame desde el menú del JDesktopPane este vaya al frente y tenga ya pueda operar con el. Ahora mismo se abre pero necesito ejecutar un click primero para que se seleccione el iframe y otro segundo click ya para operar en el jInternalFrame. Quiero que directamente se seleccione en el momento que se abra y pueda operar con el sin tener que darle dos click.

Metodo donde debería añadir alguna linea para que funcione:
( Lo que esta comentado ya lo he probado )

private void menuInicioMouseReleased(java.awt.event.MouseEvent evt) {
if (vIni.isVisible()) {
try {
vIni.setMaximum(false);
vIni.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
//try{
jdEscritorio.add(vIni);

//vIni.toFront();
//vIni.moveToFront();
//vIni.setSelected(true);
//vIni.setEnabled(Boolean.TRUE);
// try{
//vIni.setSelected(true);
// } catch (java.beans.PropertyVetoException e){
// trate a excecao...
// }
vIni.show();

//vIni.setFocusable(true);
//vIni.requestFocus();
//}catch (PropertyVetoException ex) {
// Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
//}
}

}

private void menuInicioMouseClicked(java.awt.event.MouseEvent evt) {
if (vIni.isVisible()) {
try {
vIni.setMaximum(false);
vIni.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
//try{
jdEscritorio.add(vIni);

//vIni.toFront();
//vIni.moveToFront();
//vIni.setSelected(true);
//vIni.setEnabled(Boolean.TRUE);

vIni.show();

}
}


Codigo completo :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Principal;

import java.awt.Frame;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author systen
*/
public class vAdmin extends javax.swing.JFrame {

public static vInternaUsuarios vUsu;
public static vInternaRegistro vReg;
public static vInicio vIni;
public static prue vPrue;

public vAdmin() {

initComponents();
this.vIni = new vInicio();
this.vUsu = new vInternaUsuarios();
this.vReg = new vInternaRegistro();
this.vPrue = new prue();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

lblUsuario = new javax.swing.JLabel();
jPanelPrincipal = new javax.swing.JPanel();
jScrollPanePrincipal = new javax.swing.JScrollPane();
jdEscritorio = new javax.swing.JDesktopPane();
mBSuperior = new javax.swing.JMenuBar();
menuInicio = new javax.swing.JMenu();
menuRegistro = new javax.swing.JMenu();
mIAdministrador = new javax.swing.JMenu();
sbMenuIncidencias = new javax.swing.JMenuItem();
sbMenuTienda = new javax.swing.JMenuItem();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("VentaAdministrador");
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setMaximumSize(new java.awt.Dimension(1920, 1080));
setPreferredSize(new java.awt.Dimension(1000, 600));

jPanelPrincipal.setMaximumSize(new java.awt.Dimension(1920, 1080));
jPanelPrincipal.setPreferredSize(new java.awt.Dimension(1000, 600));

jScrollPanePrincipal.setCursor(new java.awt.Cursor(java.awt.Cursor.MOVE_CURSOR));
jScrollPanePrincipal.setMaximumSize(new java.awt.Dimension(1920, 1080));
jScrollPanePrincipal.setPreferredSize(new java.awt.Dimension(1000, 600));

jdEscritorio.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jdEscritorio.setMaximumSize(new java.awt.Dimension(1920, 1080));
jdEscritorio.setPreferredSize(new java.awt.Dimension(1000, 600));

javax.swing.GroupLayout jdEscritorioLayout = new javax.swing.GroupLayout(jdEscritorio);
jdEscritorio.setLayout(jdEscritorioLayout);
jdEscritorioLayout.setHorizontalGroup(
jdEscritorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, Short.MAX_VALUE, Short.MAX_VALUE)
);
jdEscritorioLayout.setVerticalGroup(
jdEscritorioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, Short.MAX_VALUE, Short.MAX_VALUE)
);

jScrollPanePrincipal.setViewportView(jdEscritorio);
//jScrollPane1.getVerticalScrollBar().setBlockIncrement(500);
jScrollPanePrincipal.getVerticalScrollBar().setUnitIncrement(16);

javax.swing.GroupLayout jPanelPrincipalLayout = new javax.swing.GroupLayout(jPanelPrincipal);
jPanelPrincipal.setLayout(jPanelPrincipalLayout);
jPanelPrincipalLayout.setHorizontalGroup(
jPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelPrincipalLayout.createSequentialGroup()
.addComponent(jScrollPanePrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0))
);
jPanelPrincipalLayout.setVerticalGroup(
jPanelPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanelPrincipalLayout.createSequentialGroup()
.addComponent(jScrollPanePrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0))
);

jScrollPanePrincipal.getAccessibleContext().setAccessibleName("");

mBSuperior.setMaximumSize(new java.awt.Dimension(221, 200));

menuInicio.setText("Inicio");
menuInicio.addMenuListener(new javax.swing.event.MenuListener() {
public void menuCanceled(javax.swing.event.MenuEvent evt) {
}
public void menuDeselected(javax.swing.event.MenuEvent evt) {
}
public void menuSelected(javax.swing.event.MenuEvent evt) {
menuInicioMenuSelected(evt);
}
});
menuInicio.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
menuInicioMouseClicked(evt);
}
public void mouseReleased(java.awt.event.MouseEvent evt) {
menuInicioMouseReleased(evt);
}
});
menuInicio.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuInicioActionPerformed(evt);
}
});
mBSuperior.add(menuInicio);

menuRegistro.setText("Registro");
menuRegistro.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
menuRegistroMouseClicked(evt);
}
});
mBSuperior.add(menuRegistro);

mIAdministrador.setText("Administrador");

sbMenuIncidencias.setText("Incidencias");
sbMenuIncidencias.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sbMenuIncidenciasActionPerformed(evt);
}
});
mIAdministrador.add(sbMenuIncidencias);

sbMenuTienda.setText("Usuarios");
sbMenuTienda.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sbMenuTiendaActionPerformed(evt);
}
});
mIAdministrador.add(sbMenuTienda);

mBSuperior.add(mIAdministrador);

setJMenuBar(mBSuperior);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanelPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

private void menuInicioMenuSelected(javax.swing.event.MenuEvent evt) {

}

private void sbMenuIncidenciasActionPerformed(java.awt.event.ActionEvent evt) {

/*
if(vInci.isVisible()) {
try {
vInci.setMaximum(false);
vInci.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
jdEscritorio.add(vInci);
vInci.show();



}
*/
}

private void sbMenuTiendaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// if(inci.isShowing() ) {
//mensaje de que está abierto si se desea
if (vUsu.isVisible()) {
try {
vUsu.setMaximum(false);
vUsu.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
jdEscritorio.add(vUsu);
vUsu.show();

//inci.limpiarLista();
// inci.llenarLista();
/*
vUsu.mostrarIncidenciasPropias("");
vUsu.mostrarUsuariosIncidencias("");
vUsu.mostrarTodasLasIncidencias();
vUsu.botonesCrear();
*/
}
}

private void menuRegistroMouseClicked(java.awt.event.MouseEvent evt) {

/*
if(vPrue.isVisible()) {
try {
vPrue.setMaximum(false);
vPrue.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
jdEscritorio.add(vPrue);
vPrue.show();



}

*/
/*
if(vReg.isVisible()) {
try {
vReg.setMaximum(false);
vReg.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
jdEscritorio.add(vReg);
vReg.show();
}*/
}

private void menuInicioActionPerformed(java.awt.event.ActionEvent evt) {
/*
if(vIni.isVisible()) {
try {
vIni.setMaximum(false);
vIni.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
jdEscritorio.add(vIni);
vIni.show();
}*/
}

private void menuInicioMouseReleased(java.awt.event.MouseEvent evt) {
if (vIni.isVisible()) {
try {
vIni.setMaximum(false);
vIni.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
//try{
jdEscritorio.add(vIni);

//vIni.toFront();
//vIni.moveToFront();
//vIni.setSelected(true);
//vIni.setEnabled(Boolean.TRUE);
try{
vIni.setSelected(true);
} catch (java.beans.PropertyVetoException e){
// trate a excecao...
}
vIni.show();

//vIni.setFocusable(true);
//vIni.requestFocus();
//}catch (PropertyVetoException ex) {
// Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
//}
}

}

private void menuInicioMouseClicked(java.awt.event.MouseEvent evt) {
if (vIni.isVisible()) {
try {
vIni.setMaximum(false);
vIni.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(vAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
//try{
jdEscritorio.add(vIni);

//vIni.toFront();
//vIni.moveToFront();
//vIni.setSelected(true);
//vIni.setEnabled(Boolean.TRUE);

vIni.show();

}
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(vAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(vAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(vAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(vAdmin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new vAdmin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanelPrincipal;
private javax.swing.JScrollPane jScrollPanePrincipal;
public static javax.swing.JDesktopPane jdEscritorio;
public static javax.swing.JLabel lblUsuario;
private javax.swing.JMenuBar mBSuperior;
private javax.swing.JMenu mIAdministrador;
private javax.swing.JMenu menuInicio;
private javax.swing.JMenu menuRegistro;
private javax.swing.JMenuItem sbMenuIncidencias;
private javax.swing.JMenuItem sbMenuTienda;
// End of variables declaration
}

enero 3, 2018 | Registered Commentertiegor