Приложение Swing Экспортированная банка увеличивает размер - PullRequest
0 голосов
/ 18 октября 2018

Когда я запускаю Swing-приложение, размер окна составляет 600 * 400, а в строке заголовка - 617 * 445.

Но когда я экспортировал его как Runnable Jar (с той же конфигурацией запуска), размер изменяется на 767 * 546, включая строку заголовка.Значки изображений в JPanel увеличиваются и не становятся резкими.

В JPanel I

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(); 
            }
        });
    }

}   
...