我正在使用JFrame创建虚拟钢琴,使用按钮来表示按键。
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(94, 94, 94).addComponent(
jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 46,
javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
这就是我的想法
答案 0 :(得分:0)
使用分层窗格,它支持组件的重叠,但您可以操作窗格以使组件彼此非常接近而不会重叠。
JLayeredPane overlap = new JLayeredPane();
getContentPane().add(overlap);
// then you overlap.add(ITEM YOU WANT, new Integer(1));
//integers determine how you want what to overlap in an ordered fashion