我是一名初学者,正在构建一个带按钮和滚动条的简单窗口.当我编译我的代码时,我的按钮上的文字被删除了一个省略号,图像图标没有显示.我试过在eclipse和NetBeans中编译它.为了解决我试过的问题
.setMargin(new Insets(0, 0, 0, 0));
.setPreferedSize
adding padding (I forgot the code for this)
.setBounds
Run Code Online (Sandbox Code Playgroud)
以及我在互联网上偶然发现的其他一切.这些都没有解决我的问题,我无法查看按钮中的文本和图像.
我的代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FeedBar2 extends JFrame {
public FeedBar2() {
super("FeedBar 2");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// create icons
ImageIcon loadIcon = new ImageIcon("load.gif");
ImageIcon saveIcon = new ImageIcon("save.gif");
ImageIcon subscribeIcon = new ImageIcon("subscribe.gif");
ImageIcon unsubscribeIcon = new ImageIcon("unsubscribe.gif");
// create buttons
JButton load = new JButton("Load", loadIcon);
JButton save = new JButton("Save", saveIcon);
JButton subscribe = new JButton("Subscribe", subscribeIcon); …Run Code Online (Sandbox Code Playgroud)