View unanswered posts | View active topics It is currently Wed Apr 26, 2017 1:22 am



Reply to topic  [ 1 post ] 
 Need button to stay at the bottom of my dialog 
Author Message

Joined: Tue Dec 13, 2011 12:17 pm
Posts: 3
Post Need button to stay at the bottom of my dialog
Hi,

I tried to extend the "initial example" from the MigLayout whitepaper in order to add an "OK" button that would always stay on the bottom of the dialog:

Image

Unfortunately, the only solution I found was to add a "fake label" that would grow:

Code:
public class TestResize extends JDialog {
    protected JPanel contentPane;

    public TestResize() {
        super((Dialog) null, "Test resize", true);
        setupUI();
        setContentPane(contentPane);
    }

    private void setupUI() {
        contentPane = new JPanel(new MigLayout());
        contentPane.add(new JLabel("Enter size:"), "");
        contentPane.add(new JTextField(""), "grow, pushx, wrap");
        contentPane.add(new JLabel("Enter weight:"), "");
        contentPane.add(new JTextField(""), "grow, pushx, wrap");
        // fake panel that is allowed to grow
        contentPane.add(new JPanel(), "span 2, grow, pushy, wrap");
        JButton okButton = new JButton("Ok");
        JPanel buttonPanel = new JPanel(new MigLayout("", "[center, grow]"));
        buttonPanel.add(okButton, "");
        contentPane.add(buttonPanel, "dock south");
    }

    public static void main(String[] args) {
        TestResize dialog = new TestResize();
        dialog.pack();
        dialog.setVisible(true);
    }
}


I really don't like this approach at all... but is there a better way ?

Thanks !


Wed Dec 14, 2011 12:22 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.