hondz
发贴: 4
积分: 0
|
于 2007-09-05 11:17
把工具栏添加到窗口中后,工具栏成了一个细条条,摆弄了很长时间没有弄好。add(toolBar, BorderLayout.PAGE_START);我也用了add(toolBar, BorderLayout.NORTH );也是一样。大家遇到过这种情况吗?
下面是我的部分代码,大侠们帮我看看:
public class TestGraphicsShiftFrame extends JFrame { private JToolBar toolBar=new JToolBar(); private DrawingPanel drawPanel=new DrawingPanel(); private DrawLine toolLine; private DrawRectangle toolRect; private DrawSideBoard toolCube; /** * The constructor. */ public TestGraphicsShiftFrame() { JMenuBar menuBar = new JMenuBar(); JMenu menuFile = new JMenu(); JMenuItem menuFileExit = new JMenuItem(); menuFile.setLabel("File"); menuFileExit.setLabel("Exit"); // Add action listener.for the menu button menuFileExit.addActionListener ( new ActionListener() { public void actionPerformed(ActionEvent e) { TestGraphicsShiftFrame.this.windowClosed(); } } ); menuFile.add(menuFileExit); menuBar.add(menuFile); setTitle("TestGraphicsShift"); setJMenuBar(menuBar); addButtons(); setSize(new Dimension(500, 500)); add(toolBar, BorderLayout.PAGE_START); JScrollPane scrollPane=new JScrollPane(); scrollPane.setViewportView(drawPanel); add(scrollPane,BorderLayout.CENTER); // Add window listener. this.addWindowListener ( new WindowAdapter() { public void windowClosing(WindowEvent e) { TestGraphicsShiftFrame.this.windowClosed(); } } ); } private void addButtons(){ toolLine=new DrawLine(drawPanel); toolRect=new DrawRectangle(drawPanel); toolCube=new DrawSideBoard(drawPanel); toolBar.add(new Default(drawPanel)); toolBar.add(toolLine); toolBar.add(toolRect); toolBar.add(toolCube); toolBar.addSeparator(); toolBar.add(new ZoomIn(drawPanel)); toolBar.add(new ZoomOut(drawPanel)); } protected void windowClosed() { System.exit(0); } }
|