-1

when I double click the swing jar,it displays normal .button,textfield and label are displayed as expected. enter image description here but after some time,JPanel is automaticly resized to minimum as below shows. I have already set frame setResizable(false) enter image description here anyone can give some ideas?

    public TestSwing() {
        super(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        log = new JTextArea(18, 45);
        log.setMargin(new Insets(5, 5, 5, 5));
        log.setEditable(true);
        logScrollPane = new JScrollPane(log);
        DefaultCaret caret = (DefaultCaret) log.getCaret();
        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

        btn_source = new JButton("open");
        btn_dest = new JButton("open");
        lbl_sourceFile = new JLabel("Source Excel File:");
        lbl_destFile = new JLabel("Destination XML Folder:");
        txt_source = new JTextField(45);
        txt_dest = new JTextField(45);
        btn_convert = new JButton("Convert");

        c.fill = GridBagConstraints.VERTICAL;
        c.insets = new Insets(0, 0, 0, 0);
        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 1;
        add(lbl_sourceFile, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 1;
        c.gridy = 0;
        c.gridwidth = 1;
        add(txt_source, c);

        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 2;
        c.gridy = 0;
        c.insets = new Insets(0, 10, 2, 0);
        c.gridwidth = 1;
        add(btn_source, c);
    }

    public void actionPerformed(ActionEvent e) {}

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("TestLink Converter");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new TestSwing());
        frame.setLocationRelativeTo(null);
        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.FALSE);
                createAndShowGUI();
            }
        });
    }
}
Venus
  • 1,184
  • 2
  • 13
  • 32
  • Added the java tag in order to draw more attention to this question. – deHaar Dec 05 '18 at 10:34
  • 1) For better help sooner, [edit] to add 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). – Andrew Thompson Dec 05 '18 at 10:47

1 Answers1

1
frame.add(new TLSwing());

We don't know what "TLSing()" class is, but I would guess it is a panel that uses a GridBagLayout. When there is no enough space to show the component at its preferred size, the component will be displayed at its minimum size so your text components shrink.

I have already set frame setResizable(false)

You should set the resize state BEFORE you pack() the frame.

frame.setResizable(false);
frame.pack();
frame.setVisible(true);
//frame.setResizable(false);
camickr
  • 321,443
  • 19
  • 166
  • 288