秋千应用出口罐子扩大尺寸

时间:2018-10-18 12:21:58

标签: java eclipse swing executable-jar

当我“运行方式” Swing应用程序时,窗口的尺寸为600 * 400,包括标题栏的尺寸为617 * 445。

但是当我将其导出为Runnable Jar(具有相同的启动配置)时,尺寸更改为767 * 546(包括标题栏)。 JPanel中的图像图标会放大并且不清晰。

在JPanel中,我做

setPreferredSize(new Dimension(600, 400));

添加尺寸比较。

Dimension Difference

在下面填写代码。

public class SelfServiceGreeny extends JPanel
                        implements ActionListener {
protected JRadioButton b1, b2, b3, b4, b5, b6;
GridLayout gridLayout = new GridLayout(0, 3); // one row 3 buttons, 2 rows 6 buttons

    public SelfServiceGreeny() {

        setLayout(gridLayout);
        setOpaque(true);
        ImageIcon b1Icon = createImageIcon("b1.png"); // One image per button, total 6 buttons, each of size 200*200, 
        ....
        b1 = new JRadioButton(b1Icon);
        b1.setRolloverIcon(b1HoverIcon);
        b1.setSelectedIcon(b1SelectedIcon);
        b1.setActionCommand("b1");
        b1.setBorder(BorderFactory.createEmptyBorder());
        b1.setContentAreaFilled(false);
        ......
        .......
        b1.addActionListener(this);
        ......
        ......

        b1.setToolTipText("Click b1.");
        ....
        .....

        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(b1);
        ....
        ....

        add(b1);        
        ....
        ....
    }

    private static void createAndShowGUI() {

        //Create and set up the window.
        JFrame frame = new JFrame("Self Service Portal");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        SelfServiceGreeny newContentPane = new SelfServiceGreeny();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        ImageIcon favicon = createImageIcon("/images/Logo.png");
        frame.setIconImage(favicon.getImage());
        frame.setResizable(false);

        //Display the window.
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI(); 
            }
        });
    }

}   

0 个答案:

没有答案