View unanswered posts | View active topics It is currently Thu Feb 23, 2017 4:58 pm



Reply to topic  [ 1 post ] 
 Cells extend to the left, instead of the right. 
Author Message

Joined: Thu Apr 12, 2012 8:52 pm
Posts: 2
Post Cells extend to the left, instead of the right.
See sample code.

In the first row the components are r and l justified in their cells. In the second row the cell is spanned and pushed to the right.

All of the excess space in the first row is given to cell 0,0 which contains the component labelled "20". Tab "Two" improves the situation by using pushx.

But how do I give all the excess space to cell 0, 1 (the cell containing the component labelled "30")?

I have attached an image for what I desire.

Code:
package test1;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import net.miginfocom.swing.MigLayout;

public class Main extends JTabbedPane {
   
   public Main() {
      addTab("One",   createPanel1());
      addTab("Two",   createPanel2());

   }
   public static void main(String[] args) {
       final JFrame frame = new JFrame("Test MigLayout");
       Main main = new Main();
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setContentPane(main);
       SwingUtilities.invokeLater(new Runnable() {
           @Override
         public void run() {
              frame.pack();
               frame.setVisible(true);
               frame.setBounds(200, 200, 800, 500);
           }
       });
   }
   
   private JPanel createPanel1() {
      JPanel       panel         = new JPanel(new MigLayout("hidemode 3, debug", "[r][l]"));
      JTextField textField1 = new JTextField("20", 20);
      JTextField textField2 = new JTextField("30", 30);
      JButton button = new JButton("Button");
      panel.add(textField1);
      panel.add(textField2, "wrap");
      panel.add(button, "span 2, pushx");
      return (panel);
   }
   private JPanel createPanel2() {
      JPanel       panel         = new JPanel(new MigLayout("hidemode 3, debug", "[r][l]"));
      JTextField textField1 = new JTextField("20", 20);
      JTextField textField2 = new JTextField("30", 30);
      JButton button = new JButton("Button");
      panel.add(textField1);
      panel.add(textField2, "pushx, wrap");
      panel.add(button, "span 2, pushx");
      return (panel);
   }

}


Attachment:
Desired layout.jpg
Desired layout.jpg [ 44.9 KiB | Viewed 22077 times ]


Mon Feb 04, 2013 8:10 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.