Java—我找不到有效的值
我想知道我的申请是否能得到一些帮助。如果不把所有的东西都塞满,我就找不到正确的价值观。它使用GridBagConstraint、JPanel、JScrollPane(在其中一个面板上不起作用)、JButton、JTabbedPane和JTextArea。下面是填充显示屏的相关代码。JPanel的TabBar和FileViewer扩展以及JFrame的窗口扩展 选项卡的初始化以及如何添加选项卡。(这不是JScrollPane填充部分) 这是JScrollPane的拼凑版。。。现在我并不担心,但最终会的。我逐个面板添加到面板。添加(按钮) 这里是我创建窗口的地方。这就是需要帮助的地方。我不知道我应该设定什么值。我已经看过了文档以及这些类是如何工作的Java—我找不到有效的值,java,swing,user-interface,layout-manager,gridbaglayout,Java,Swing,User Interface,Layout Manager,Gridbaglayout,我想知道我的申请是否能得到一些帮助。如果不把所有的东西都塞满,我就找不到正确的价值观。它使用GridBagConstraint、JPanel、JScrollPane(在其中一个面板上不起作用)、JButton、JTabbedPane和JTextArea。下面是填充显示屏的相关代码。JPanel的TabBar和FileViewer扩展以及JFrame的窗口扩展 选项卡的初始化以及如何添加选项卡。(这不是JScrollPane填充部分) 这是JScrollPane的拼凑版。。。现在我并不担心,但最终
private WindowComponent() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.exit(1);
}
setSize(new Dimension(1024, 900));
setLocationRelativeTo(null);
setTitle("GridBagConstraints");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
setJMenuBar(new MenuBarComponent());
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 1;
c.anchor = GridBagConstraints.NORTHWEST;
add(FileViewerComponent.getInstance(), c);
c = new GridBagConstraints();
c.gridwidth = 2;
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 1;
c.anchor = GridBagConstraints.NORTHEAST;
add(TabBarComponent.getInstance(), c);
addWindowListener(this);
setVisible(true);
}
谢谢你对我的帮助
第一张图片是原始尺寸,第二张是我把窗户缩小的时候。当我放大窗户时,它工作得很好
编辑:我可以使用java创建的API部分或工具吗?请解释,1)你试图实现什么,2)你得到什么,3)请显示任何和所有错误消息(如果有),4)请发布一个。我的网速很慢。。。上传图片要花很长时间。不要使用GridBagLayout。将工具栏组件添加到BorderLayout.WEST,将文件查看器组件添加到BorderLayout.CENTER。
public FileViewerComponent() {
super(new GridLayout(0, 1, 5, 0));
instance = this;
panel = new JPanel();
panel.setLayout(new GridLayout(0, 1, 5, 0));
scrollArea = new JScrollPane(panel);
addButtons();
add(scrollArea);
}
private WindowComponent() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.exit(1);
}
setSize(new Dimension(1024, 900));
setLocationRelativeTo(null);
setTitle("GridBagConstraints");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
setJMenuBar(new MenuBarComponent());
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 1;
c.anchor = GridBagConstraints.NORTHWEST;
add(FileViewerComponent.getInstance(), c);
c = new GridBagConstraints();
c.gridwidth = 2;
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.5;
c.weighty = 1;
c.anchor = GridBagConstraints.NORTHEAST;
add(TabBarComponent.getInstance(), c);
addWindowListener(this);
setVisible(true);
}