[英]JFrame text components not showing up properly
我今天正在玩JFrame並且無法讓JButton組件正確顯示文本。 JButton中顯示的文本最后被截斷。 我嘗試調整JButton組件的大小以確保文本適合,但發生了同樣的問題。 問題看起來像這樣:
這是代碼:
import javax.swing.JFrame;
public class Launcher {
public static void main(String[] args) {
JFrame jFrame = new JFrame("Frame");
jFrame.setSize(400, 400);
jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE);
jFrame.setLocation(400, 400);
jFrame.add(new Drawable(jFrame));
jFrame.setVisible(true);
}
}
這是另一個.java文件中的另一個類。
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Drawable extends JPanel {
private JButton button;
private JFrame jFrame;
public Drawable(JFrame jFrame) {
this.jFrame = jFrame;
button = new JButton("This text does not show properly");
button.setPreferredSize(new Dimension(200, 25));
button.setLocation(jFrame.getWidth() / 2 - 50, jFrame.getHeight() / 2 - 12);
this.add(button);
}
}
我知道這可能是我的項目設置的問題,所以如果有人需要我發布它我可以這樣做。
刪除聲明
button.setPreferredSize(new Dimension(200, 25));
面板的布局管理器使用它來約束按鈕寬度
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.