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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:04:03+00:00 2026-05-25T15:04:03+00:00

Hey (: This is my first time asking help on this forum so I

  • 0

Hey (: This is my first time asking help on this forum so I hope I have done everything correctly

Okay my problem is what I have marked with red. My JPanel uses a Boxlayout with BoxLayout.Y_AXIS orientation. I guess that is not the right choise. I don’t want my JPanel(online users), my JSeperator and my other JPanel(admin) to be apart of eachother. I want them to stack directly under eachother.

Pic of GUI: http://dl.dropbox.com/u/10049103/notcool.png

I have heard that I should be able to use some kind of “glue” but could not get that to work as intended. I also heard that I had to use GridBagLayout but that seems very complicated and I would really like if there is an easier way.

Here is the code for the marked JPanel (don’t know if needed):

package Client;

import Server.User;
import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;

/**
 *
 * @author Sune
 */
public class OnlineUsersPanel extends JPanel {
private UserWindow owner; public void setOwner(UserWindow uw) { owner = uw; }
private HashMap<String, ShowUserPanel> userPanels = new HashMap<String, ShowUserPanel>();

public OnlineUsersPanel() {
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    this.add(addStart());
    this.add(new JSeparator());
    System.out.println("OnlineUsersPanel con called");
}

void addUser(User user) {
    ShowUserPanel newPanel = new ShowUserPanel(owner, user.getUserName());
    userPanels.put(user.getUserName(), newPanel);
    this.add(newPanel);
    owner.updateGUI();
}

void deleteUser(User user) {
    ShowUserPanel toRemove;

    for (Iterator i = userPanels.keySet().iterator(); i.hasNext();) {
        String tempUserName = (String) i.next();
        if (tempUserName.equals(user.getUserName())) {
            toRemove = userPanels.remove(tempUserName);
            this.remove(toRemove);
            System.out.println("Fundet og fjernet");
            break;
        }
    }
}

private JPanel addStart() {
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(new JLabel("Online Users:"), BorderLayout.LINE_START);
    p.add(new JLabel("mute:"), BorderLayout.LINE_END);
    return p;
}

I hope someone can learn me how to use that glue properly or tell me the good way to do this (:

  • 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-25T15:04:04+00:00Added an answer on May 25, 2026 at 3:04 pm

    Edit: changed to an answer:

    The panels are right on top of each other. The question is what kind of layout is being used by the container holding the two JPanels? Also are you doing to display many users? Do you need a JList or JTable there? Can you show a picture of what you want the gui to look like, and show it when there are a typical number of users. Also consider creating and posting an SSCCE. This would take a bit of work on your part, but would be well worth it.

    Edit 1:
    On further review of your image, I suggest that you use a JTable here with “Online Users” and “Mute” as your column headings and with the stuff you currently show below, the Admin and the checkbox as a row of the JTable. Put it in a JScrollPane and display it where you’re currently displaying it.

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

Sidebar

Related Questions

Hey, first time poster on this awesome community. I have a regular expression in
Hey There, This is a pretty simple problem, but it is my first time
Hey dudes.i am having this problem while symlinking. I have successfully deployed a ruby
Hey all this is the first time i am calling a stored procedure via
Hey guys, this is my first time actually posting at stackflow but i've used
Hey everyone.. This is my first time writing an ASP.NET MVC web app, and
Hey, first time asking a question on Stack Overflow, so go easy on me!
Hey this is my first time trying anything like so I don't know if
Hey Everyone. I'm a first time poster, but I've browsed this site a number
Hey guys, This is my first time making an app with any kind of

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.