【发布时间】:2014-08-22 20:03:20
【问题描述】:
我已经找了很多次但我没有找到它,很抱歉,如果之前已经回答过这个问题,但我认为没有。我正在为游戏制作一个客户端商店,我有界面、图像、一切,当我在中间设置文本时,它显示得非常好。
但如果我将文本设置为显示在底部,它会这样做:http://prntscr.com/4ffdn9 我正在使用:
shopButton.setHorizontalTextPosition(JLabel.CENTER);
shopButton.setVerticalTextPosition(JLabel.BOTTOM);
设置让我感到困惑的文本,但这不是主要问题。我还需要在屏幕上的框中有一个图像,这是我用来创建按钮的函数:
public void createBuyButton(final JButton shopButton, JLabel image, BufferedImage sprite, int x, int y, int width, int height, int i){
shopButton.setIcon(new ImageIcon(cropImage(sprite, button.getButtonRect("BUYBUTTON"))));
shopButton.setRolloverIcon(new ImageIcon(cropImage(sprite, button.getButtonRect("BUYBUTTON_OVERLAY"))));
shopButton.setText(shopItems.getNameOfItems()[i]);
shopButton.setHorizontalTextPosition(JLabel.CENTER);
shopButton.setVerticalTextPosition(JLabel.BOTTOM);
shopButton.setBounds(x, y, width, height);
image.add(shopButton);
return;
}
我正在使用 for 循环来遍历我拥有的所有按钮。我将如何在背景图像上添加另一个图像,以便它在我没有悬停在它上面以及当我悬停在它上面时显示?如果您需要更多信息,请告诉我,我会尽快回复。
【问题讨论】:
标签: java image user-interface jbutton settext