View unanswered posts | View active topics It is currently Mon May 01, 2017 1:29 am



Reply to topic  [ 3 posts ] 
 Grow a textField 
Author Message

Joined: Wed Jun 30, 2010 6:34 pm
Posts: 3
Post Grow a textField
Hi,

I'm using MigLayout version 3.7.3 and I have 4 components aligned into 2 rows. The first row contains a label, textfield and a button and the second row contains a textarea that is spanned over 3 columns.

I need the cells that hold the label and button to take exactly the size of those 2 components all the other space will be given to the textfield, as in the below image
Attachment:
expected.JPG
expected.JPG [ 12.92 KiB | Viewed 9063 times ]


But I'm currently getting an empty space between the label and the textfield as below
Attachment:
result.JPG
result.JPG [ 23.76 KiB | Viewed 9063 times ]


Below is an example:
Code:
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;


public class GrowTextField extends JFrame {
    public GrowTextField() {
        JPanel panel = new JPanel(new MigLayout("fill, debug"));
        getContentPane().add(panel);
       
        JLabel label = new JLabel("Description");
        panel.add(label, "cell 0 0");
       
        JTextField textField = new JTextField();
        panel.add(textField, "cell 1 0, growx, pushx");
       
        JButton button = new JButton("Go!");
        panel.add(button, "cell 2 0");
       
        JTextArea textArea = new JTextArea();
        panel.add(textArea, "cell 0 1, span, grow, push");
       
        setVisible(true);
        setExtendedState(MAXIMIZED_BOTH);
    }


    public static void main(String[] args) {
        new GrowTextField();
    }
}


could you please advice?

Thank you


Wed Jun 30, 2010 7:06 pm
Profile
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Grow a textField
Hello,

Since the TextArea has its base in the first column it will make that column inherit the push. Try to change the push to pushy for the TA and see if that helps.

Cheers,
Mikael


Wed Jun 30, 2010 7:22 pm
Profile WWW

Joined: Wed Jun 30, 2010 6:34 pm
Posts: 3
Post Re: Grow a textField
It works

Thank you


Thu Jul 01, 2010 10:29 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

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.