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 8321101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:54:06+00:00 2026-06-08T22:54:06+00:00

Here is the code of my Layout class. import java.awt.event.*; import java.awt.*; import javax.swing.*;

  • 0

Here is the code of my Layout class.

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class Layout extends JFrame {
    private JButton lb;
    private JButton cb;
    private JButton pb;
    private FlowLayout layout;
    private Container container;

    public Layout() {
        super("The Title");
        layout = new FlowLayout();
        container = new Container();
        setLayout(layout);

        //*Left
        lb = new JButton("L");
        add(lb);
        lb.addActionListener(
            new ActionListener(){   
                public void actionPerformed(ActionEvent event){
                    layout.setAlignment(FlowLayout.LEFT);
                    layout.layoutContainer(container);
                }
            }
        );
        //*Center
        cb = new JButton("C");
        add(cb);
        cb.addActionListener(
            new ActionListener(){   
                public void actionPerformed(ActionEvent event){
                    layout.setAlignment(FlowLayout.CENTER);
                    layout.layoutContainer(container);
                }
            }
        );      
        //*Right
        pb = new JButton("R");
        add(pb);
        pb.addActionListener(
            new ActionListener(){   
                public void actionPerformed(ActionEvent event){
                    layout.setAlignment(FlowLayout.RIGHT);
                    layout.layoutContainer(container);
                }
            }
        );
    }
}

I’m learning java through thenewboston youtube tutorials (this code is from this tutorial). But this one doesn’t work like it should. When I click the right button (R) it should drag all the buttons to the right side of the window instantly. It doesnt. However when I click that right button and then forcibly resize the window then it do what it should. By adding setResizable(false) in the main method I cant resize the program so it doesnt work.
What have I done wrong?

Forgive me for my poor English btw.

  • 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-06-08T22:54:09+00:00Added an answer on June 8, 2026 at 10:54 pm

    replace

    container = new Container();
    

    by

    container = getContentPane();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's an SSCCE: import java.awt.Color; import java.awt.Dimension; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import
Here is my code: package com.AndroidCustomDialog; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException;
Here is my code... import java.util.ArrayList; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import android.app.Activity; import android.content.Intent;
Android crashes whenever this activity is started. here is the code. import java.util.ArrayList; import
here is my code... package sortarray.com; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle;
here is my mysql and php code layout: I have 3 tables tableA stores
Here's my layout code; <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent> <TextView android:text=@string/welcome
enter code here I have a ListView that have a different Layout XML for
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
Here is my code: chartDialog = new Dialog(item_activity.this); chartDialog.setContentView(R.layout.customlayout); chartDialog.setTitle(Title ); TextView textItemDetailsDialog =

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.