GridBagLayout & setting JPanel to appear in specific location

Posted on 2006-03-29
Last Modified: 2012-06-27

I am using the gridbagLayout. I have a JPanel, a JTable, and another JPanel in that appear in that order down the screen.
The problem is, I want the first JPanel to appear nearer the top left hand corner of the screen, It appears 1/2 way down the screen. Which forces the JTable further down.
Can I fix the setting of this JPanel.
I tried setLocation(10,10); but it didnt solve it for me.

Could anyone offer advice.

Question by:ShamD
    LVL 86

    Expert Comment

    You'll need to post your code, preferably runnable
    LVL 30

    Expert Comment

    Did you put it in a scroll-pane? If yes, then you need to set the location/ bounds to the scroll-pane (not to the panel).
    LVL 24

    Accepted Solution

    To distribute the objects ,  set weighty to 1 in the GridBagConstraints

    LVL 92

    Expert Comment

    > I tried setLocation(10,10); but it didnt solve it for me.

    to set the location you need to use null layout manager.
    And you'll also need to set the size

    Author Comment

    Thanks for your responses.
    I just needed to alter my GridbagConstraints inputs.
    I wasnt sure how to use them before and what they all meant.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    dividesSelf challange 15 60
    Basics of Drool Rule Engine with few samples 2 31
    json format text only 4 50
    java set up 1 37
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now