JToolBar调整大小

时间:2013-12-03 16:35:11

标签: java swing icons jbutton toolbar

我已经为jframe添加了一个jtoolbar,其中包含一个用于启动的jbutton init。但是,虽然按钮尺寸较大,但工具栏显得太小,按钮几乎不显示。我怎样才能解决这个问题? 在框架中我有一个带有图像jlabel作为背景的jpanel,然后我在CENTER的jlabel中添加了2个按钮。最后,我在jlabel的PAGE_START中添加了jtoolbar。

enter image description here

public class bcquery extends JPanel implements ActionListener {


    static JFrame frame = new JFrame("BIOCORE - GAMS Tool");
    static JLabel labelimg;
    public bcquery() throws IOException {


        setLayout(new BorderLayout());

        File file = new File(".jpg");           

        labelimg = new JLabel(new ImageIcon(ImageIO.read(file)));
        labelimg.setPreferredSize(new Dimension(1000, 300));

        add(labelimg);

         labelimg.setLayout(new BorderLayout());


final JButton button1 = new JButton("OK");

final JButton button2 = new JButton("CLEAR");

JPanel btnpanel = new JPanel(new FlowLayout());
        btnpanel.add(button1);
        btnpanel.add(button2);

btnpanel.setOpaque(false);

labelimg.add(btnpanel, BorderLayout.CENTER);


public static void createToolBar() { 


        JToolBar toolbar = new JToolBar("Applications");
        JButton btn = new JButton(new ImageIcon(".jpg"));
        btn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("test");

            }
        });

        toolbar.add(btn);
        labelimg.add(toolbar, BorderLayout.PAGE_START);

    }

    private static void createAndShowGUI() throws IOException {

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);           
            frame.setSize(500, 500);
            JFrame.setDefaultLookAndFeelDecorated(true);

            frame.add(new bcquery());
            frame.setResizable(false);

            frame.pack();
            frame.setVisible(true);
        }

        public static void main(String[] args) {

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {

                UIManager.put("swing.boldMetal", Boolean.TRUE);


            try {
                createAndShowGUI();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
                }
            });

    }
        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub

        }
}

0 个答案:

没有答案