bom dia,
Tenho uma JFrame, que por sua vez contém um JLayeredPanel e que por sua vez contém 3 JPanels, cada um com um botão.
Eles estão sobrepostos uns sobre os outros. Quando passo o mouse por cima da primeira camada ele consegue acessar os botões que estão oultos nas camadas de trás.
Alguém sabe como posso evitar que os componentes dos paineis de tras possam ficar inacessíveis enquanto ocultos?
segue codigo.
[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package guilabs;
/**
*
-
@author Jucélio Horácio Vieira
*/
public class Camadas extends javax.swing.JFrame {/**
- Creates new form Camadas
*/
public Camadas() {
initComponents();
}
/**
-
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”)
//
private void initComponents() {jLayeredPane1 = new javax.swing.JLayeredPane();
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jPanel3 = new javax.swing.JPanel();
jButton3 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLayeredPane1.setEnabled(false);
jLayeredPane1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLayeredPane1MouseClicked(evt);
}
});
jLayeredPane1.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentMoved(java.awt.event.ComponentEvent evt) {
jLayeredPane1ComponentMoved(evt);
}
});jPanel1.setBackground(new java.awt.Color(0, 102, 204));
jPanel1.setDoubleBuffered(false);
jPanel1.setFocusable(false);jButton1.setText(“jButton1”);
jButton1.setDefaultCapable(false);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});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()
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(66, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
);jPanel1.setBounds(20, 10, 100, 100);
jLayeredPane1.add(jPanel1, javax.swing.JLayeredPane.MODAL_LAYER);jPanel3.setBackground(new java.awt.Color(0, 204, 0));
jButton3.setText(“jButton2”);
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(66, Short.MAX_VALUE)
.addComponent(jButton3)
.addContainerGap())
);jPanel3.setBounds(50, 30, 100, 100);
jLayeredPane1.add(jPanel3, javax.swing.JLayeredPane.MODAL_LAYER);jPanel2.setBackground(new java.awt.Color(255, 255, 0));
jButton2.setText(“jButton2”);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(66, Short.MAX_VALUE)
.addComponent(jButton2)
.addContainerGap())
);jPanel2.setBounds(80, 50, 100, 100);
jLayeredPane1.add(jPanel2, javax.swing.JLayeredPane.MODAL_LAYER);javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(47, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(58, Short.MAX_VALUE))
);pack();
}//
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jLayeredPane1.moveToFront(jPanel1);
}private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
jLayeredPane1.moveToFront(jPanel3);
}private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
jLayeredPane1.moveToFront(jPanel2);
}private void jLayeredPane1MouseClicked(java.awt.event.MouseEvent evt) {
System.out.println(“mouse click”);
}private void jLayeredPane1ComponentMoved(java.awt.event.ComponentEvent evt) {
System.out.println(“Componente foi movido”); // TODO add your handling code here:
}/**
-
@param args the command line arguments
/
public static void main(String args[]) {
/- Set the Nimbus look and feel
/
//
/ - 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(Camadas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Camadas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Camadas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Camadas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/*
-
Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {public void run() {
new Camadas().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLayeredPane jLayeredPane1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
// End of variables declaration
}
[/code]
- Set the Nimbus look and feel
- Creates new form Camadas