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

  • SEARCH
  • Home
  • 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 6232121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:03:45+00:00 2026-05-24T10:03:45+00:00

I am struggling controlling my components. I hava a JFrame which contains a JPanel.

  • 0

I am struggling controlling my components. I hava a JFrame which contains a JPanel. My components such as JLabel and JTextArea are added to this Panel. So my question is:

How can I control these compontens? I’ve tried using

GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 1;

But it doesn’t seems to work..

Here is my function the initialize my GUI:

public void initGUI()
{

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  

    final JFrame frame = new JFrame("instantINFO!");
                 frame.setSize(screenSize.width, screenSize.height); 
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 frame.setLayout(new GridBagLayout()); 

    final JPanel panel = new JPanel();

    weather = new JTextArea(vær, 6, 20);
    weather.setFont(new Font("Arial", Font.BOLD, 16));
    weather.setLineWrap(true);
    weather.setWrapStyleWord(true);
    weather.setOpaque(false);
    weather.setEditable(false);

    stedLabel = new JLabel(sted);
    dagLabel = new JLabel(dag);

    panel.add(weather);
    panel.add(stedLabel); 
    panel.add(dagLabel); 

    frame.add(panel);
    frame.setVisible(true);

}

For instance I want the weather label to be in the left upper corner, with a few pixels of margin.

  • 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-24T10:03:47+00:00Added an answer on May 24, 2026 at 10:03 am

    A JPanel uses a FlowLayout by default. And by default components are centered in a row on the panel. If you want the components left aligned then you need to change the flow layout to left align the components. Read the FlowLayout API to see how to do this.

    I also suggest you look at the Swing tutorial on Using Layout Managers for working examples.

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

Sidebar

Related Questions

im struggling with syntax here: hopefully this question is v simple, im just miising
Im struggling with this one. I have a list of items and on a
Iam struggling with NHibernate and its lazyload. I have a structure which I simplified
Been struggling with this simple selector problem a couple of hours now and must
Struggling with this one. I have set up a basic email/enquiry form for a
Struggling with this tournament fixtures algorithm. The code is working perfectly but I need
Im struggling to create a functionality which keeps on incrementing css property of an
Struggling with this problem for an hour now and searched both stackoverflow and google
still struggling with regex :) i have this code: $link = '/\bhttp:\/\/.+\..+[\/\w]?\b/i'; $match =
really struggling to resolve this issue. using nhibernate Im trying to join two different

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.