Java 使用Swing将工具栏添加到框架
我试图制作一个框架,并在页面开始处添加一个工具栏,在底部添加一个状态栏,以及一个可以显示内部框架的桌面。但我只是得到一个空的框架。我做错了什么 谢谢Java 使用Swing将工具栏添加到框架,java,swing,Java,Swing,我试图制作一个框架,并在页面开始处添加一个工具栏,在底部添加一个状态栏,以及一个可以显示内部框架的桌面。但我只是得到一个空的框架。我做错了什么 谢谢 public class AdminStart extends JFrame implements ActionListener{ private JToolBar toolBar; private JDesktopPane desktop; private StatusBar statusBar; private JPanel panel;
public class AdminStart extends JFrame implements ActionListener{
private JToolBar toolBar;
private JDesktopPane desktop;
private StatusBar statusBar;
private JPanel panel;
//this is a class that i created and extends JToolBar
private ToolBarAdmin miToolBar;
private String ID = null;
private String type = null;
private String state = null;
public AdministradorInicio(String ID, String tipo, String estado){
super("Start");
setExtendedState(JFrame.MAXIMIZED_BOTH);
//setSize(JFrame.MAXIMIZED_HORIZ, JFrame.MAXIMIZED_VERT);
//setResizable(false);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.ID = ID;
this.tipo = type;
this.estado = state;
toolBar = new JToolBar();
miToolBar = new ToolBarAdmin();
desktop = new JDesktopPane();
statusBar = new StatusBar();
panel = new JPanel();
for(int i = 0; i < miToolBar.toolBarTitles.length; i++){
miToolBar.boton[i].addActionListener(this);
}
panel.setLayout(new BorderLayout());
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
toolBar.setFloatable(false);
toolBar.add(miToolBar);
desktop.setBackground(Color.DARK_GRAY);
panel.add(toolBar, BorderLayout.PAGE_START);
panel.add(desktop, BorderLayout.CENTER);
panel.add(statusBar, BorderLayout.PAGE_END);
add(panel);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
}
public static void main(String[] args) {
new AdminStart("sdsd","sdsd","sdsd");
}
}
公共类AdminStart扩展JFrame实现ActionListener{
专用工具栏;
私人JDesktopPane桌面;
私有状态栏状态栏;
私人JPanel小组;
//这是我创建并扩展JToolBar的一个类
私人酒吧;
私有字符串ID=null;
私有字符串类型=null;
私有字符串状态=null;
公共管理员(字符串ID、字符串tipo、字符串estado){
超级(“启动”);
setExtendedState(JFrame.MAXIMIZED_两者);
//设置大小(JFrame.MAXIMIZED_HORIZ,JFrame.MAXIMIZED_VERT);
//可设置大小(假);
setLayout(空);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.ID=ID;
this.tipo=类型;
this.estado=状态;
工具栏=新的JToolBar();
miToolBar=新工具栏管理员();
桌面=新的JDesktopPane();
statusBar=新的statusBar();
panel=新的JPanel();
对于(int i=0;i
这会伤害到你:
setLayout(null);
使用
null
布局时,编码人员完全负责指定每个组件的位置和大小。您也会得到非常严格的GUI,几乎不可能维护或升级,在一个系统和屏幕分辨率上看起来不错,但在其他地方可能会很糟糕。此外,正如程序员所说,“像素完美布局在现代ui设计中是一种幻觉。”解决方案是,摆脱setLayout(null)
,努力避免使用null
布局。你是对的。谢谢在编辑代码后,我忘了删除它。