Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:46:00+00:00 2026-05-26T09:46:00+00:00

I want to make a Firefox like Option Dialog in Java with Swing. I

  • 0

I want to make a Firefox like Option Dialog in Java with Swing.

I tried now to align all my elements on the north of the Window. I made it with the first element, but the next Elements are filling the room vertically and are not aligned.
For this i’m using the GridBagLayout.

Here is the code:

import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;


public class Background {  

    private Border headBorder = BorderFactory.createEmptyBorder(15, 8, 10, 8);
    private GridBagConstraints headPaneConstrain;
    private JPanel headPane;


    public Background() {

        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                JFrame dialog = new JFrame();

                //headPane
                dialog.add(headPane());

                //2 elements
                createSetting("test");
                createSetting("test2");

                //dialog settings
                dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                dialog.setSize(500,500);
                dialog.setVisible(true);                
            }
        });


    }

    private JPanel createSetting(String name) {
        JPanel panel = new JPanel();
        panel.setBorder(BorderFactory.createTitledBorder(name));
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        headPane.add(panel,headPaneConstrain);
        return panel;
    }

    private JPanel headPane(){
      //Constrain
        headPaneConstrain = new GridBagConstraints();
        headPaneConstrain.fill = GridBagConstraints.HORIZONTAL;
        headPaneConstrain.anchor = GridBagConstraints.NORTH;
        headPaneConstrain.weightx = 1.0;
        headPaneConstrain.weighty = 1.0;
        headPaneConstrain.gridx=0;

        //HeadPane
        headPane = new JPanel();
        headPane.setBorder(headBorder);
        headPane.setLayout(new GridBagLayout());
        return headPane;
    }


    public static void main(String[] args) {  
       new Background();  
    }  

}  

Thanks for help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:46:00+00:00Added an answer on May 26, 2026 at 9:46 am

    If you don’t want your ” inner” panels to grow vertically, then why do you set weigthy to 1.0? You should set it to 0.0 instead (at least for all panels that should not grow vertically).

    Besides, please pay attention that using borders will have an impact on alignments of components between 2 panels.

    A better way to show different “sections” in a form is to use only one panel for the whole form and separate sections with a Jlabel followed by a horizontal JSeparator.

    For this kind of form, I would use DesignGridLayout (rather than GridBagLayout which is too much of a PITA to get what you want…), but I’m biased here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a dropdown menu like delicious has at this http://delicious.com/search?context=all&p=sql&lc=1 page.
I'm trying to make a combo box that behaves somewhat like the Firefox 3
I want to make a new widget javascript class [Label] it look like dijit.button.
I want to make sure that the structur of my form is like that:
I want to make a YAHOO.util.Connect.asyncRequest call, which not is async. Just like open(method,
I'd like to make an XML document in JavaScript then have a save dialog
I really want to make use of multiple background support (Webkit, Firefox 3.6+), but
How can I get the window name? I want to make a script where
I want make datetimepicker in my project. Using jquery how it is possible? I
Let's say I want make some of my sources publicly available via my blog

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.