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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:32:43+00:00 2026-06-05T00:32:43+00:00

Why is the label not displaying? package javaapplication4; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout;

  • 0

Why is the label not displaying?

package javaapplication4;


import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class settingPanel extends javax.swing.JPanel {
    static JPanel con = new JPanel();
    static JFrame frame = new JFrame();
    JLabel jLabel1 = new JLabel();
    public JEditorPane htmlvi = new JEditorPane();

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

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4",
                    "Item 5" };

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jList1ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jList1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
                jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel1Layout
                        .createSequentialGroup()
                        .addComponent(jScrollPane1,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(325, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 272,
                Short.MAX_VALUE));

        jTabbedPane1.addTab("tab1", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400,
                Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300,
                Short.MAX_VALUE));
    }// </editor-fold>

    private void addpanel() {
        JPanel pnl = new JPanel();
        pnl.setOpaque(false);
        pnl.setLayout(new GridBagLayout());
        pnl.add(new JButton());
        pnl.setVisible(true);
        jPanel1.setLocation(10, 30);
        jPanel1.add(pnl);
    }

    private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {

        JLabel write = new JLabel();

        // if(evt.getValueIsAdjusting()){
        String read = "<html><h2>" + jList1.getSelectedValue().toString()
                + "<UL>USB";
        addpanel();

        jPanel1.add(write);

    }

    // Variables declaration - do not modify
    private javax.swing.JList jList1;
    public static javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;

    // End of variables declaration
    public static void main(String args[]) {

        frame.add(new settingPanel());
        // jPanel2.setLayout(new GridBagLayout());
        // jPanel2.add(new JButton());
        // jPanel2.setVisible(false);
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(3);
    }
}
  • 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-05T00:32:45+00:00Added an answer on June 5, 2026 at 12:32 am

    You add your JLabel to jPanel1, which uses a GroupLayout to display its components. The GroupLayout needs to know where each component must be placed in its vertical and horizontal group, and it doesn’t know where to put your new label, since you didn’t tell.

    I very much doubt that your end goal is to add a new label to your GUI each time the selection changes. You should probably add a unique label with a default text when the GUI is initialized, and change the text of this label when the selection changes.

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

Sidebar

Related Questions

I'm not having much luck centering vertically the label I'm adding to the TitleView
How can I set label's border which is dynamically generated (Not from Interface Builder)?
How to fix the label for Gateway, which is the only one not showing.
I would like a button to change a label between being visible and not
<label for=input>Label</label><input type=file id=input/> In Firefox 7 it is not possible to trigger the
When setting the title attribute in Zend_Form, this is not being translated. (Label &
This works: <asp:Label ID=asdf runat=server Text='<%# Eval(Image1) %>'></asp:Label> displaying data like: L8_Pic_1.jpg This doesn't:
Part of my PHP form is not displaying with jQuery Mobile. The form seems
I am not having success displaying an image at a node in dot. My
I have a label at the top of my UIView.I am displaying some messages

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.