Buscar
Social
Ofertas laborales ES

Foro sobre Java SE > Visibilidad de componentes

Buenos días,
He estado comprobando que si durante la ejecución quiero modificar la visibilidad de un componente puedo hacerlo perfectamente pero si dejo puesto de serie la visibilidad a false luego en tiempo de ejecución por más que le diga visible(true) no lo hace

octubre 29, 2013 | Registered CommenterElena

Debe hacerlo. Hay algo extraño en tu código.
Eso "de serie"... los componentes se pueden hacer visibles o invisibles en cualquier momento.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test extends javax.swing.JFrame {

/** Creates new form Test */
public Test() {
initComponents();
jLabel1.setVisible(false);

jToggleButton1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
jLabel1.setVisible(jToggleButton1.isSelected());
}
});
}

/** 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() {

jToggleButton1 = new javax.swing.JToggleButton();
jLabel1 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.FlowLayout());

jToggleButton1.setText("Test");
getContentPane().add(jToggleButton1);

jLabel1.setText("Visibilidad");
getContentPane().add(jLabel1);

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

/**
@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(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new Test().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JToggleButton jToggleButton1;
// End of variables declaration
}

octubre 29, 2013 | Registered Commenterchoces

Cuando digo "de serie" quiero decir que al inicializar la clase digo que ese componente sea visible(false) y entonces luego al intentar hacerlo true no me funciona, esta tarde pongo aquí el código para que lo podáis ver

octubre 29, 2013 | Registered CommenterElena

Eso es exactamente lo que hace el código de prueba que te he puesto:
- el componente se hace invisible, después de crearlo, en el constructor del JFrame.
- una vez inicializado y visible el JFrame, el JLabel se puede hacer visible o invisible pulsando el botón, mediante el ActionListener creado.

octubre 29, 2013 | Registered Commenterchoces

He probado lo que me has puesto pero no sé qué pasa que inicialmente al ejecutar la aplicación está visible el label y el cuadro de texto y tengo que habilitar y deshabilitar el botón para que empiece a desaparecer. Esto es lo que hago:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
* @since 16 Octubre 2013
* @author MCHG
*/
public class mEfectivo extends javax.swing.JDialog {
private int mode;

/**
* Creates new form mEfectivo
*/
public mEfectivo(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();

jToggleButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblPrice.setVisible(jToggleButton1.isSelected());
jTxtPrice.setVisible(jToggleButton1.isSelected());
}
});
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPCash = new javax.swing.JPanel();
lblPrice = new java.awt.Label();
jPanelSeparator = new javax.swing.JPanel();
jPanelSeparator2 = new javax.swing.JPanel();
jTxtConcept = new javax.swing.JTextField();
jTxtPrice = new javax.swing.JTextField();
jCBVueltas = new javax.swing.JCheckBox();
lblConcept = new java.awt.Label();
jToggleButton1 = new javax.swing.JToggleButton();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
setType(java.awt.Window.Type.UTILITY);

jPCash.setBackground(new java.awt.Color(255, 255, 204));

lblPrice.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
lblPrice.setText("Precio:");

jPanelSeparator.setBackground(new java.awt.Color(0, 0, 0));
jPanelSeparator.setBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(255, 255, 255), new java.awt.Color(255, 204, 204)));
jPanelSeparator.setPreferredSize(new java.awt.Dimension(267, 7));

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

jPanelSeparator2.setBackground(new java.awt.Color(0, 0, 0));
jPanelSeparator2.setBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(255, 255, 255), new java.awt.Color(255, 204, 204)));
jPanelSeparator2.setPreferredSize(new java.awt.Dimension(267, 7));

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

jTxtPrice.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
jTxtPrice.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTxtPrice.setText("0");
jTxtPrice.setEnabled(false);

jCBVueltas.setBackground(new java.awt.Color(255, 255, 204));
jCBVueltas.setSelected(true);
jCBVueltas.setText("Vueltas");
jCBVueltas.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jCBVueltasMouseClicked(evt);
}
});

lblConcept.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
lblConcept.setText("Concepto");

jToggleButton1.setText("jToggleButton1");

javax.swing.GroupLayout jPCashLayout = new javax.swing.GroupLayout(jPCash);
jPCash.setLayout(jPCashLayout);
jPCashLayout.setHorizontalGroup(
jPCashLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPCashLayout.createSequentialGroup()
.addGroup(jPCashLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
.addComponent(jPanelSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
.addGroup(jPCashLayout.createSequentialGroup()
.addContainerGap()
.addGroup(jPCashLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTxtConcept)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPCashLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(lblConcept, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(117, 117, 117)))))
.addGap(238, 238, 238))
.addGroup(jPCashLayout.createSequentialGroup()
.addGroup(jPCashLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPCashLayout.createSequentialGroup()
.addGap(143, 143, 143)
.addComponent(jCBVueltas))
.addGroup(jPCashLayout.createSequentialGroup()
.addGap(113, 113, 113)
.addComponent(lblPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTxtPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPCashLayout.createSequentialGroup()
.addGap(95, 95, 95)
.addComponent(jToggleButton1)))
.addContainerGap())
);
jPCashLayout.setVerticalGroup(
jPCashLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPCashLayout.createSequentialGroup()
.addGap(57, 57, 57)
.addComponent(lblConcept, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTxtConcept, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jCBVueltas)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanelSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jToggleButton1)
.addGap(30, 30, 30)
.addGroup(jPCashLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTxtPrice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(107, 107, 107))
);

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

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


/**
* Método main a través del cual se ejecuta todo el jDialog Valija.
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
mEfectivo dialog = new mEfectivo(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {

@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JCheckBox jCBVueltas;
private javax.swing.JPanel jPCash;
private javax.swing.JPanel jPanelSeparator;
private javax.swing.JPanel jPanelSeparator2;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JTextField jTxtConcept;
private javax.swing.JTextField jTxtPrice;
private java.awt.Label lblConcept;
private java.awt.Label lblPrice;
// End of variables declaration
}

octubre 30, 2013 | Registered CommenterElena

Creo que hay un problema con el layout.
¿Podrías publicar el .form también, para que pueda cargarlo en el Editor Gráfico?

octubre 30, 2013 | Registered Commenterchoces

Lo ejecuto así directamente y lo edito eso con Netbeans

octubre 30, 2013 | Registered CommenterElena

Es un problema con el layout.
¿No has creado el JDialog con el Editor Gráfico de NetBeans?. Si lo has creado con él, debes tener el archivo .form de esa clase, junto con el .java, en la misma carpeta. Sin ese archivo es extremadamente difícil detectar un problema de layout.

He creado un test donde puedes comprobar que puede funcionar como quieres. El JDialog está creado con el Editor Gráfico de NetBeans.

package utiles;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
<p>
@author Administrator
*/
public class Test extends javax.swing.JDialog {

/** Creates new form Test */
public Test(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
jLabel1.setVisible(false);
jTextField1.setVisible(false);

jToggleButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final boolean seleccionado = jToggleButton1.isSelected();
jLabel1.setVisible(seleccionado);
jTextField1.setVisible(seleccionado);

}
});

}

/** 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() {

jToggleButton1 = new javax.swing.JToggleButton();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

jToggleButton1.setText("Prueba");

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel1.setText("Precio");

jTextField1.setEditable(false);
jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTextField1.setText("0");

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)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jToggleButton1))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jToggleButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

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

/**
@param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Test dialog = new Test(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JToggleButton jToggleButton1;
// End of variables declaration
}

octubre 31, 2013 | Registered Commenterchoces

No sé como puedo mandarte un privado con un enlace para que puedas descargar el proyecto tal y como lo tengo yo pero no puedo así que te lo dejo aquí colgado porque por mucho que busco, no encuentro el .form que me dices:

http://www.mediafire.com/?23p6qy355vgcgwf

octubre 31, 2013 | Registered CommenterElena

Estará en la misma carpeta que la clase .java, con el mismo nombre que la clase, pero con la extensión .form
No lo verás desde NetBeans, sino con el explorador de archivos del sistema.

Ya he descargado la aplicación desde ese enlace. La voy a mirar con detenimiento, y ya te contaré.

octubre 31, 2013 | Registered Commenterchoces

Lo he resuelto usando GridBagLayout.
Te copio a continuación, los archivos .java y .form

octubre 31, 2013 | Registered Commenterchoces

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
@since 16 Octubre 2013
@author Manuel Chana García
*/
public class mEfectivo extends javax.swing.JDialog {

private int mode;

/**
Creates new form mEfectivo
*/
public mEfectivo(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();

lblPrice.setVisible(false);
jTxtPrice.setVisible(false);
jToggleButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
lblPrice.setVisible(jToggleButton1.isSelected());
jTxtPrice.setVisible(jToggleButton1.isSelected());
}
});
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;

jPCash = new javax.swing.JPanel();
jPanelSeparator = new javax.swing.JPanel();
jPanelSeparator2 = new javax.swing.JPanel();
jTxtConcept = new javax.swing.JTextField();
jTxtPrice = new javax.swing.JTextField();
lblPrice = new java.awt.Label();
jCBVueltas = new javax.swing.JCheckBox();
lblConcept = new java.awt.Label();
jToggleButton1 = new javax.swing.JToggleButton();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
setType(java.awt.Window.Type.UTILITY);

jPCash.setBackground(new java.awt.Color(255, 255, 204));
jPCash.setLayout(new java.awt.GridBagLayout());

jPanelSeparator.setBackground(new java.awt.Color(0, 0, 0));
jPanelSeparator.setBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(255, 255, 255), new java.awt.Color(255, 204, 204)));
jPanelSeparator.setPreferredSize(new java.awt.Dimension(267, 7));

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

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 9;
gridBagConstraints.ipadx = 410;
gridBagConstraints.ipady = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(7, 10, 0, 10);
jPCash.add(jPanelSeparator, gridBagConstraints);

jPanelSeparator2.setBackground(new java.awt.Color(0, 0, 0));
jPanelSeparator2.setBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(255, 255, 255), new java.awt.Color(255, 204, 204)));
jPanelSeparator2.setPreferredSize(new java.awt.Dimension(267, 7));

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

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 9;
gridBagConstraints.ipadx = 410;
gridBagConstraints.ipady = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
jPCash.add(jPanelSeparator2, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 8;
gridBagConstraints.ipadx = 337;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 10);
jPCash.add(jTxtConcept, gridBagConstraints);

jTxtPrice.setFont(new java.awt.Font("Times New Roman", 0, 11)); // NOI18N
jTxtPrice.setHorizontalAlignment(javax.swing.JTextField.CENTER);
jTxtPrice.setText("0");
jTxtPrice.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 7;
gridBagConstraints.gridy = 4;
gridBagConstraints.ipadx = 169;
gridBagConstraints.ipady = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 0);
jPCash.add(jTxtPrice, gridBagConstraints);

lblPrice.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
lblPrice.setText("Precio:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 4;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 0);
jPCash.add(lblPrice, gridBagConstraints);

jCBVueltas.setBackground(new java.awt.Color(255, 255, 204));
jCBVueltas.setSelected(true);
jCBVueltas.setText("Vueltas");
jCBVueltas.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jCBVueltasMouseClicked(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
jPCash.add(jCBVueltas, gridBagConstraints);

lblConcept.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
lblConcept.setText("Concepto");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 0, 0);
jPCash.add(lblConcept, gridBagConstraints);

jToggleButton1.setText("jToggleButton1");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridheight = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(11, 10, 11, 0);
jPCash.add(jToggleButton1, gridBagConstraints);

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

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

private void jSP001PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP002PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP005PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP010PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP020PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP050PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP1PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP2PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP5PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP10PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP20PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP50PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP100PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP200PropertyChange(java.beans.PropertyChangeEvent evt) {

}

private void jSP500PropertyChange(java.beans.PropertyChangeEvent evt) {

}

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

}

/**
Método main a través del cual se ejecuta todo el jDialog Valija.
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
mEfectivo dialog = new mEfectivo(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {

@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JCheckBox jCBVueltas;
private javax.swing.JPanel jPCash;
private javax.swing.JPanel jPanelSeparator;
private javax.swing.JPanel jPanelSeparator2;
private javax.swing.JToggleButton jToggleButton1;
private javax.swing.JTextField jTxtConcept;
private javax.swing.JTextField jTxtPrice;
private java.awt.Label lblConcept;
private java.awt.Label lblPrice;
// End of variables declaration
}

octubre 31, 2013 | Registered Commenterchoces

<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="resizable" type="boolean" value="false"/>
<Property name="type" type="java.awt.Window$Type" editor="org.netbeans.modules.form.editors.EnumEditor">
<Value id="UTILITY"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPCash" alignment="0" pref="434" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPCash" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPCash">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="ff" red="ff" type="rgb"/>
</Property>
</Properties>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanelSeparator">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="0" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder>
<Color PropertyName="highlight" blue="ff" green="ff" red="ff" type="rgb"/>
<Color PropertyName="shadow" blue="cc" green="cc" red="ff" type="rgb"/>
</EtchetBorder>
</Border>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[267, 7]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="2" gridWidth="9" gridHeight="1" fill="0" ipadX="410" ipadY="3" insetsTop="7" insetsLeft="10" insetsBottom="0" insetsRight="10" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="3" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Container class="javax.swing.JPanel" name="jPanelSeparator2">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="0" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder>
<Color PropertyName="highlight" blue="ff" green="ff" red="ff" type="rgb"/>
<Color PropertyName="shadow" blue="cc" green="cc" red="ff" type="rgb"/>
</EtchetBorder>
</Border>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[267, 7]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="3" gridWidth="9" gridHeight="1" fill="0" ipadX="410" ipadY="3" insetsTop="6" insetsLeft="10" insetsBottom="0" insetsRight="10" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>

<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="3" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Component class="javax.swing.JTextField" name="jTxtConcept">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="0" gridWidth="8" gridHeight="1" fill="0" ipadX="337" ipadY="0" insetsTop="11" insetsLeft="10" insetsBottom="0" insetsRight="10" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="jTxtPrice">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Times New Roman" size="11" style="0"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="0"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="7" gridY="4" gridWidth="1" gridHeight="1" fill="0" ipadX="169" ipadY="2" insetsTop="11" insetsLeft="10" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="java.awt.Label" name="lblPrice">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Times New Roman" size="14" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Precio:"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="3" gridY="4" gridWidth="4" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="11" insetsLeft="10" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="jCBVueltas">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Vueltas"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jCBVueltasMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="3" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="10" insetsLeft="10" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="java.awt.Label" name="lblConcept">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Times New Roman" size="14" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Concepto"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="10" insetsLeft="10" insetsBottom="0" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JToggleButton" name="jToggleButton1">
<Properties>
<Property name="text" type="java.lang.String" value="jToggleButton1"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="4" gridWidth="2" gridHeight="2" fill="0" ipadX="0" ipadY="0" insetsTop="11" insetsLeft="10" insetsBottom="11" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

octubre 31, 2013 | Registered Commenterchoces

Muchas gracias, acabo de probarlo y ya me funciona.
¿Cómo puedo cambiarlo en el resto de formularios que tengo? Porque he cambiado el Layout en un formulario pulsando en el jPanel con el botón derecho del ratón y seleccionando en el apartado "Activar gestor de distribución" el "Diseño de bolsillo de rejilla" que es el GridBagLayout pero sigue sin funcionar.
Perdón por se tan pesado con eso, jeje

noviembre 3, 2013 | Registered CommenterElena

Pues no sé por qué no te funciona en otros formularios.
Asegúrate de que los componentes que quieras hacer invisibles, estén incluidos en el GridBag.

noviembre 3, 2013 | Registered Commenterchoces