在flowlayout中更改JButton的重叠

时间:2015-01-27 19:07:57

标签: java swing jbutton layout-manager flowlayout

如何重复最后一张最右边的卡片,最左边的那张卡片,以便重叠将会反转?

所以我在flowlayout中有一个包含JButtons的JPanel。我想模仿拿着卡片的感觉,所以我重叠了JButtons。问题是JButton图像的重叠是这样的,数字只出现在右下角,我希望它们在左上角。 这就是我现在所拥有的:

enter image description here

ZOrdering没有工作,它只是颠倒了卡的顺序(另一方面的王牌,王者等等)。我想要的是重复最后一张最右边的牌,最左边一张,这样重叠就会反转。

修改 构建手的代码:

hand= new JPanel();
    hand.setLayout(new FlowLayout(FlowLayout.CENTER, -45, 0));
    hand.setOpaque(false);
    for(int i=0; i<p1.getHand().size(); i++){
        JButton te=new JButton();
        //button customization, icons and such
        te.addActionListener(this);
        //here I tried the ZOrdering that didn't work
        //hand.setComponentZOrder(te, 0)
        hand.add(te);
    }
    this.add(hand);
    }
    //yes, the setBounds is long and weird 
    hand.setBounds(WINDW/2-((p1.getHand().size())*CARDWHAND*2/5), WINDH-CARDHHAND-30, p1.getHand().size()*CARDWHAND*4/5+50, CARDHHAND+30);

此布局管理器为空

1 个答案:

答案 0 :(得分:3)

查看支持此功能的OverlapLayout

您可能还想使用JLabel而不是JButton。上面的链接将解释按钮的潜在问题,虽然我认为只有在使用按钮的边框时才会出现此问题。