我想使用它的按钮,但我的按钮没有我想要的文本JFrame!我将它设置在按钮构造函数中,然后用setText设置,但它仍然不显示!此外,按钮填充整个框架,有没有办法让它不坚持JFrame的边缘?JButton不显示文字;填充JFrame
import javax.swing.*;
public class main
{
public static void main(String[] args)
{
JFrame mainWindow = new JFrame("8 Game");
mainWindow.setSize(200, 200);
JButton eightButton = new JButton("8");
eightButton.setText("8");
eightButton.setSize(30, 30);
eightButton.setBounds(5, 5, 25, 25);
eightButton.setContentAreaFilled(false);
eightButton.setAction(new buttonAction());
mainWindow.add(eightButton);
mainWindow.setVisible(true);
}
}
一个JFrame的默认布局管理器是BorderLayout,它并不真正关心你在你的JButton设定的范围。 –
看看[如何使用按钮](http://docs.oracle.com/javase/tutorial/uiswing/components/button.html) – nachokk