我目前正在制作一个类似国际象棋的棋盘游戏,所以我制作了一个 11*11 的场地。在每个字段上都应该有一个 JButton(在默认层上),并且在更高的层上是一个可移动的 JLabel。但标签仍将按钮推开。这是简化的代码:
public class Demo {
public static void main(String[] args) {
ImageIcon image = new ImageIcon("C:src\\myImage.png");
JFrame frame = new JFrame();
JPanel mainPanel = new JPanel();
JLayeredPane[] tileLayeredPane = new JLayeredPane[121];
JButton button = new JButton();
JLabel label = new JLabel();
label.setIcon(image);
button.setText("I am not visible!");
for (int i = 0; i < tileLayeredPane.length; i++) { // creates 121 JLabels
tileLayeredPane[i] = new JLayeredPane();
tileLayeredPane[i].setLayout(new BoxLayout(tileLayeredPane[i], BoxLayout.Y_AXIS));
tileLayeredPane[i].setOpaque(true);
}
tileLayeredPane[0].add(button, JLayeredPane.DEFAULT_LAYER);
tileLayeredPane[0].add(label, JLayeredPane.PALETTE_LAYER);
mainPanel.setLayout(new GridLayout(11, 11));
for(int i = 0; i < 121; i++) {
mainPanel.add(tileLayeredPane[i]);
}
frame.add(mainPanel);
frame.setVisible(true);
}
}
JLabel中的多行文字
前端人员升管理层有哪些岗位
选中选区之后,Ctrl+C复制,然后在另一个图层取消选区?
java 读取xls表格然后实现上一页和下一页 (写了出来但是不能用,不知道为什么,封装另外的类中)
相关分类