在JToolbar上垂直添加JButton

时间:2013-04-27 09:49:11

标签: java swing jtable jbutton jtoolbar

我想在JToolbar上添加更多按钮,但我无法在垂直方向上添加按钮1;而是他们自动水平对齐。

public class Interface 
{
JTable tableT = new JTable();
private JTable table;

  public Interface()
  {
   final JFrame f= new JFrame("Content Provider Generator");
   f.setFont(new Font("Aharoni", Font.BOLD, 12));
   f.setForeground(Color.GRAY);
   f.getContentPane().setBackground(Color.WHITE);

     JToolBar toolBar = new JToolBar();
      f.getContentPane().add(toolBar, BorderLayout.EAST);

  //MenuButton//
      JButton button = new JButton();
button.setIcon(new ImageIcon
        (Interface.class.getResource("/javax/swing/plaf/metal/icons/ocean/menu.gif")));
      toolBar.add(button);   //added to JToolbar

      JPopupMenu popupMenu = new JPopupMenu();
      addPopup(button, popupMenu);

      //Jpopupmenu
      JMenuItem mntmNewMenuItem = new JMenuItem("Table");

      JButton button1 = new JButton();
    button.setIcon(newImageIcon
        (Interface.class.getResource("/javax/swing/plaf/metal/icons/ocean/menu.gif")));
      toolBar.add(button1);
}
}

1 个答案:

答案 0 :(得分:4)

请参阅JToolBar(orientation)

  

使用指定的orientation创建新工具栏。方向必须是HORIZONTALVERTICAL