0

When I "Run As" a Swing application the dimension of the window is 600*400 and including title bar it is 617*445.

But when I exported it as Runnable Jar(with same launch configuration), the dimension changes to 767*546 including title bar. The image icons within the JPanel get enlarged and are not sharp.

In JPanel I do,

setPreferredSize(new Dimension(600, 400));

Adding the comparison of dimensions.

Dimension Difference

Complete code below..

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

}   
itsraja
  • 1,640
  • 4
  • 32
  • 48
  • 1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) One way to get image(s) for an example is to hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). E.G. [This answer](https://stackoverflow.com/a/10862262/418556) hot links to an image embedded in [this question](https://stackoverflow.com/q/10861852/418556). 3) See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/q/7229226/418556) (Yes.) BTW - the panel size (relevant part) seems to have .. – Andrew Thompson Oct 18 '18 at 12:46
  • .. changed to 750 x 500. An increase of 25%. – Andrew Thompson Oct 18 '18 at 12:47
  • @AndrewThompson Added code in question. Removed setPreferredSize(..) . Did not help. Same issue. – itsraja Oct 18 '18 at 13:09
  • *"Added code in question."* That code would need imports, and lines removed, even before it would compile. It is also unnecessarily verbose with inclusion of specific `catch` blocks (instead of e.g. `catch (Exception {..`). The button group would seem to be irrelevant to the problem. Check it is, then remove it. The image is not available to anyone but you. How can anyone else run that to experiment? – Andrew Thompson Oct 18 '18 at 13:39

0 Answers0