我必须向其他人开发的Java桌面应用程序工具栏添加一些新元素。 我从未使用过Java桌面应用程序。
现在是工具栏
这应该是
由于我没有Java Swing的经验,所以我不知道如何编辑代码。
这是生成工具栏的代码:
public class Window extends JFrame implements Runnable {
....
private final JToolBar toolbar;
private final JToolBar toolbar1;
private final JPanel fbar;
private final JTextField formulaBar;
private JLabel barCaption;
JMenuBar menuBar;
RibbonBar Ribbon;
toolbar = new JToolBar();
toolbar1 = new JToolBar();
fbar = new JPanel();
formulaBar = new JTextField(70);
menuBar = new JMenuBar();
Ribbon = new RibbonBar(this);
toolbar.add(fbar);
formulaBar.setSize(500, 25);
formulaBar.setFont(new Font("Arial", Font.PLAIN, 12));
formulaBar.setBorder(BorderFactory.createCompoundBorder(formulaBar.getBorder(), BorderFactory.createEmptyBorder(0, 5, 0, 5)));
fbar.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
fbar.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
//natural height, maximum width
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.ipadx = 0;
fbar.add(Ribbon, c);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1;
c.gridy = 0;
c.ipadx = 0;
//barCaption = new JLabel(" Formula :", SwingConstants.CENTER);
barCaption = new JLabel(" ", SwingConstants.CENTER);
barCaption.setBorder(BorderFactory.createCompoundBorder(barCaption.getBorder(), BorderFactory.createEmptyBorder(0, 17, 0, 17)));
fbar.add(barCaption, c);
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0.5;
c.gridx = 2;
c.gridy = 0;
fbar.add(formulaBar, c);
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 0;
c.gridx = 0;
c.gridy = 0;
toolbar.setFloatable(false);
setJMenuBar(menuBar);
add(toolbar, BorderLayout.NORTH);
...
}
有人可以帮助我吗?