Well sounds little weird, but I am trying to overlap twoJButtons
(here jButton1
and jButton2
).I am using NetBeans GUI builder for this.Nothing extraordinary,I am using JLayeredPane to make it possible.
jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);
Well it does overlap,but the JButton
shows its self up,when Clicked by a mouse.
A screenshot will make it clear:
(take highlighted portion as a mouse pointer)
and
When the mouse pointer is clicked on the next JButton
,it comes up,hiding the first JButton.
but,I don't want the second JButton
to pop up(overlap 1stJButton
) when clicked by a mouse.
How can i do this??Well, I think this may go critical.
Here is the code,if required:
public class NewJFrame1 extends javax.swing.JFrame {
public NewJFrame1() {
initComponents();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLayeredPane1 = new javax.swing.JLayeredPane();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLayeredPane2 = new javax.swing.JLayeredPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(51, 51, 51));
jButton1.setText("jButton1");
jButton1.setBounds(0, 40, 73, 23);
jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jButton2.setText("jButton2");
jButton2.setBounds(40, 40, 73, 23);
jLayeredPane1.add(jButton2, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(98, 98, 98)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(139, 139, 139)
.addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(161, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(58, 58, 58)
.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(31, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame1().setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLayeredPane jLayeredPane1;
private javax.swing.JLayeredPane jLayeredPane2;
private javax.swing.JPanel jPanel1;
}
UPDATE :
If I am not clear, here i go again.
1) I don't want to make separate buttons,they should be overlapped .
2)Overlapping area may differ,the size of the button.
3)The second JButton should not come above the 1st JButton,when clicked.(Solution for this,but not for how to layout the buttons.)
4)There may be confusion,which button was clicked,but its ok for me.