Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do you apply GridBagLayout constraints to existing controls

  1. #1
    Junior Member
    Join Date
    Jan 2022
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default How do you apply GridBagLayout constraints to existing controls

    I use the GUI builder of NetBeans and put a panel on a frame and controls on the panel.
    How do I then apply GridBagLayout to these controls?
    I have tried re-adding the control to the panel in code but in this example changing the x,y to anything other than 0,0 makes my label disappear.
        public MyFrame() {           // constructor 
            initComponents();
            InitInputPanel();
     
        }
        private void InitInputPanel(){
            JPanel p = this.InputPanel; 
            GridBagLayout gbl = new GridBagLayout();
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridwidth = 11;
            gbc.gridheight = 84;
            gbc.gridx = 1;
            gbc.gridy = 80;
            p.add(this.lblCustomerName, gbc);
    I found lots of help using GridBagLayout and all of them build the control in code and add it to the frame.
    How do I use GridBagLayout with already placed controls?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How do you apply GridBagLayout constraints to existing controls

    My little experience with having NetBeans build any GUI is that it is very difficult to make any changes to that GUI yourself.
    Any changes to the NetBeans GUI must be done using NetBeans.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. StdDraw keyboard controls uncontrollable
    By flamboyant in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 17th, 2017, 12:19 PM
  2. Get all controls names on a layout
    By gezim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 1st, 2014, 09:14 AM
  3. Problem with Controls because of buttons
    By SagiIs in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 29th, 2011, 12:11 AM
  4. Setting constraints on a field
    By cslx99 in forum Object Oriented Programming
    Replies: 11
    Last Post: December 8th, 2011, 03:49 AM
  5. What are the constraints on the argument values?
    By colerelm in forum Java Theory & Questions
    Replies: 1
    Last Post: November 2nd, 2011, 07:15 AM