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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:37:05+00:00 2026-06-15T16:37:05+00:00

I’ve created an app but I have a problem with my JLabels not showing

  • 0

I’ve created an app but I have a problem with my JLabels not showing up properly. The app currently looks like this:

app screenshot

These are 2 JPanels inside a JFrame created with the following code:

public JFrame window = new JFrame();
public JPanel top = new JPanel();
public static JPanel main = new JPanel();
public JPanel login = new JPanel();

// ...

Inside the main class:

window.setSize(1000, 700);
login.setSize(250, 200);
//   main.setSize(500,500);
main.setLocation(500,100);

window.add(login);
window.add(main);

login.add(new view.LoginPanel());

main.setLayout(new BorderLayout());
main.add(new view.CategoryList(), BorderLayout.CENTER);
main.validate();
main.repaint();

window.validate();
window.setVisible(true);

That will show up the frames as I have them now. But above the black line there should be a title that would be created by this:

public class CategoryList extends JPanel implements MouseListener {
    public CategoryList() {
        super();
        setLayout(null);
        initComponents();
        revalidate();
        repaint();
        addTitle();
    }
}

The title is created like this:

private void addTitle() {
    JLabel lblTitle = new JLabel();
    lblTitle.setText("Winkelapplicatie");
    lblTitle.setBounds(20, 20, 150, 20);
    lblTitle.setFont(WinkelApplication.FONT_16_BOLD);
    this.add(lblTitle);
    System.out.println("addTitle");
}

But it does not show up. I know there are a lot of methods not shown in this code, but I have included what I think is all the necessary code.

I hope someone can help me, thanks in advance!

Edit:

I’ve stripped my code so it can be online:
main package:
WinkelApplication.java:

package main;


import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;



public final class WinkelApplication {

public static final String NAME = "hi";
public static final String CURRENCY = "\u20AC";
public JFrame window = new JFrame();
public JPanel top = new JPanel();
public static JPanel main = new JPanel();
public JPanel login = new JPanel();

public static final Font FONT_10_PLAIN = new Font("Verdana", Font.PLAIN, 10);
public static final Font FONT_10_BOLD = new Font("Verdana", Font.BOLD, 10);
public static final Font FONT_12_BOLD = new Font("Verdana", Font.BOLD, 12);
public static final Font FONT_16_BOLD = new Font("Verdana", Font.BOLD, 16);

private static WinkelApplication instance = new WinkelApplication();

private WinkelApplication() {
}

public void initialize() {
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        System.err.println("Error setting LookAndFeelClassName: " + e);
    }

}

public void startup() {
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setSize(1000, 700);
    login.setSize(250, 200);
     main.setLocation(500,100);
    window.add(login);
    window.add(main);
    login.add(new main.LoginPanel());  
     main.setLayout(new BorderLayout());
    main.add(new main.CategoryList(), BorderLayout.CENTER);
    main.validate();
    main.repaint();
    window.validate();
    window.setVisible(true);


}

public static WinkelApplication getInstance() {
    return instance;
}

public static void main(String args[]) {
    final WinkelApplication applicatie = WinkelApplication.getInstance();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                applicatie.initialize();
                applicatie.startup();
            } catch (Exception e) {
                System.out.println("Application" + applicatie.getClass().getName() + "failed to launch");
            }
        }
    });
}
}

LoginPanel class: (Just a textfield created with the GUI Designer in Netbeans)

  /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import main.WinkelApplication;

public class LoginPanel extends javax.swing.JPanel {

/**
 * Creates new form LoginPanel
 */
public LoginPanel() {
    initComponents();
}

private Boolean loggedIn = null;

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    javax.swing.JLabel jLabel1 = new javax.swing.JLabel();

    jLabel1.setText("TextField in JPanel 1");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(114, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel1)
            .addContainerGap(98, Short.MAX_VALUE))
    );
}// </editor-fold>                        

public Boolean isLoggedIn(){
    return loggedIn;
}
// Variables declaration - do not modify                     
// End of variables declaration                   
}

CategoryList class (Here the text should be above the line, but that does not show up)

package main;

import main.WinkelApplication;
import java.awt.Graphics;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class CategoryList extends JPanel {

public CategoryList() {
    super();
    setLayout(null);
    initComponents();
}

/** create the gui for this page */
private void initComponents() {
    addTitle();
}

/** add the page's title */
private void addTitle() {
    JLabel lblTitle = new JLabel();
    lblTitle.setText("Winkelapplicatie");
    lblTitle.setBounds(20, 20, 150, 20);
    lblTitle.setFont(WinkelApplication.FONT_16_BOLD);
    this.add(lblTitle);
    System.out.println("addTitle");
}

@Override
public void paint(Graphics graphics) {
    super.paint(graphics);
    graphics.drawLine(20, 45, 540, 45);
}
}

Hope somebody can help me now. Thanks in advance again.

  • 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-15T16:37:07+00:00Added an answer on June 15, 2026 at 4:37 pm

    I fixed this by setting the main layout also to setLayout(null), I just have to use this for this project…

    Next time when I have to write it from scratch I won’t use it!
    Anyway, thanks for helping, I would have never found the problem.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.