Results 1 to 1 of 1
  1. #1
    nat
    nat is offline Member
    Join Date
    Dec 2013
    Posts
    56
    Rep Power
    0

    Default GridBagConstraints problem

    Hi,

    I have a combo box and on the right side of it there are three more buttons. Pressing event of another button should hide these three buttons on the right side of the combo box. But then the combo box widens and I would like it to stay with fixed width, since on the right side of it I would like a label and a text box with a fixed width to appear.

    I have this code for the combo box button:

    pPaint = new JPanel();
    //getContentPane().add(pPaint, BorderLayout.NORTH);

    GridBagLayout pPaintLayout = new GridBagLayout();
    pPaintLayout.columnWidths = new int[] {7, 7, 7, 7, 7};
    pPaintLayout.rowHeights = new int[] {25};
    pPaintLayout.columnWeights = new double[] {100.0, 0.1, 0.1, 0.1, 0.1};
    pPaintLayout.rowWeights = new double[] {0.1};
    pPaint.setLayout(pPaintLayout);
    {
    cobSections = new JComboBox();
    cobSections.setRenderer(new MapSectionItemRenderer());
    pPaint.add(cobSections, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
    GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
    new Insets(0, 0, 0, 0), 0, 0));
    cobSections.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    cobSectionsActionPerformed(evt);
    }
    });
    }

    and for the label and text box I have this code:
    {
    lTimeInterval = new JLabel("interval");
    lTimeInterval.setVisible(false);
    pPaint.add(lTimeInterval, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
    GridBagConstraints.CENTER, GridBagConstraints.NONE,
    new Insets(0, 5, 0, 0), 0, 0));
    }
    {

    tfInputTinter = new JTextField();
    tfInputTinter.setVisible(false);
    pPaint.add(tfInputTinter, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
    GridBagConstraints.CENTER, GridBagConstraints.NONE,
    new Insets(0, 5, 0, 0), 0, 0));
    }

    Can anybody help me please what should I change in the code for combo bow width to stay constant, as well as text box width?

    Thank you in advance.
    Last edited by nat; 01-11-2014 at 08:40 PM.

Similar Threads

  1. Positioning items with GridBagConstraints
    By jchinson in forum AWT / Swing
    Replies: 4
    Last Post: 07-04-2011, 11:17 PM
  2. Position 5 buttons with GridBagConstraints in Swing
    By albertkao in forum AWT / Swing
    Replies: 0
    Last Post: 02-21-2011, 03:15 PM
  3. GridBagConstraints help
    By noobgrammer in forum New To Java
    Replies: 5
    Last Post: 07-03-2010, 04:12 AM
  4. [SOLVED] [newbie] java.awt.GridBagConstraints
    By jon80 in forum New To Java
    Replies: 0
    Last Post: 05-27-2009, 03:40 PM
  5. GridBagConstraints
    By Aswq in forum New To Java
    Replies: 2
    Last Post: 07-21-2008, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •