View unanswered posts | View active topics It is currently Wed May 24, 2017 5:19 am

Reply to topic  [ 2 posts ] 
 Shrink cell 
Author Message

Joined: Wed Jun 30, 2010 6:34 pm
Posts: 3
Post Shrink cell

I have a panel that contains 3 rows. The first one contains a label, the second row contains the table paging stuff and the third one contains a table.

I want the label and the table to grow onall the panel but I want to remove the empty space between the paging components, previous, next buttons and start and end page number as the expected image
expected.JPG [ 8.74 KiB | Viewed 9104 times ]

Below is what I'm getting
result.JPG [ 9.21 KiB | Viewed 9104 times ]

import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;

public class ShrinkButtons extends JFrame {
    public ShrinkButtons() {
        JPanel panel = new JPanel(new MigLayout("fill"));
        JLabel label = new JLabel("Description");
        panel.add(label, "cell 0 0, spanx 4");
        JButton previousButton = new JButton("<<");
        panel.add(previousButton, "cell 0 1");
        JTextField startField = new JTextField();
        panel.add(startField, "cell 1 1, width 20px");
        JLabel maxPages = new JLabel("/ 10");
        panel.add(maxPages, "cell 2 1");
        JButton nextButton = new JButton(">>");
        panel.add(nextButton, "cell 3 1");
        DefaultTableModel tableModel = new DefaultTableModel();
        tableModel.setDataVector(new Object[][] {{"Value 1","A"}, {"Value 2","B"}}, new Object[] {"Column 1", "Column 2"});
        JTable table = new JTable(tableModel);
        panel.add(table, "cell 0 2, spanx 4, grow, pushy");
    public static void main(String[] args) {
        new ShrinkButtons();


Thank you,

Thu Jul 01, 2010 4:01 pm
Site Admin

Joined: Mon Dec 06, 2004 4:24 pm
Posts: 2485
Location: Sweden
Post Re: Shrink cell

Since you don't have the need to align vertically in columns you can just add all components to column 0. That should do it.

Also, add "debug" to the MigLayout constructor to see the grid it lays out after. Makes everything simpler.


Fri Jul 02, 2010 12:22 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.