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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:41:40+00:00 2026-05-30T11:41:40+00:00

EDIT: Of course I find an answer 2 min after I post a question.

  • 0

EDIT:
Of course I find an answer 2 min after I post a question.
How to completely remove an icon from JDialog?

But follow-up; anyone knows the way to make consistent icon state when changing resizable property?

PS. I can’t answer my own question for 8 more hours.

ORIGINAL QUESTION:
To put it short, here is an stripped down example code which has a problem.
When I click on “Details” (WinXP x32 java 1.6) jPanel2 changes visibility state and together with jPanel2 for some reason the dialog icon is removed. Quite curious.
Anyone knows why the icon is hidden together with JPanel?
Code is generated by NetBeans 7.1, only slightly adapted to be self-contained.

Thanks in advance for help!

import java.awt.Frame;

import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class TestHide extends javax.swing.JDialog {

  private static final long serialVersionUID = 1L;

  public TestHide(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    jPanel2.setVisible(false);
    pack();
  }

  private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    lblIcon = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    taShortMsg = new javax.swing.JTextArea();
    jPanel2 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jLabel3 = new javax.swing.JLabel();
    jSeparator1 = new javax.swing.JSeparator();
    jSeparator2 = new javax.swing.JSeparator();
    jPanel4 = new javax.swing.JPanel();
    jSeparator3 = new javax.swing.JSeparator();
    jScrollPane2 = new javax.swing.JScrollPane();
    taDetails = new javax.swing.JTextArea();
    btnOk = new javax.swing.JButton();
    btnTgDetails = new javax.swing.JToggleButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    lblIcon.setText(""); // NOI18N

    jScrollPane1.setBorder(null);

    taShortMsg.setBackground(getBackground());
    taShortMsg.setColumns(20);
    taShortMsg.setEditable(false);
    taShortMsg.setFont(lblIcon.getFont());
    taShortMsg.setLineWrap(true);
    taShortMsg.setRows(5);
    taShortMsg.setBorder(null);
    taShortMsg.setCursor(getCursor());
    taShortMsg.setOpaque(false);
    jScrollPane1.setViewportView(taShortMsg);

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(lblIcon).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE).addContainerGap()));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        jPanel1Layout
            .createSequentialGroup()
            .addContainerGap()
            .addGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup().addComponent(lblIcon).addContainerGap(54, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING))));

    jPanel2.addComponentListener(new java.awt.event.ComponentAdapter() {
      public void componentHidden(java.awt.event.ComponentEvent evt) {
        jPanel2ComponentHidden(evt);
      }

      public void componentShown(java.awt.event.ComponentEvent evt) {
        jPanel2ComponentShown(evt);
      }
    });

    jLabel3.setText("jLabel3"); // NOI18N

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(jSeparator1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel3)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jSeparator2).addContainerGap()));
    jPanel3Layout
        .setVerticalGroup(jPanel3Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                jPanel3Layout
                    .createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(
                        jPanel3Layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 10,
                                javax.swing.GroupLayout.PREFERRED_SIZE))).addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE));

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        jPanel4Layout.createSequentialGroup().addContainerGap().addComponent(jSeparator3).addContainerGap()));
    jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
        jPanel4Layout.createSequentialGroup().addContainerGap().addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)));

    jScrollPane2.setBorder(null);

    taDetails.setColumns(20);
    taDetails.setEditable(false);
    taDetails.setFont(lblIcon.getFont());
    taDetails.setRows(5);
    jScrollPane2.setViewportView(taDetails);

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane2).addContainerGap())
        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        javax.swing.GroupLayout.Alignment.TRAILING,
        jPanel2Layout.createSequentialGroup()
            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 8, javax.swing.GroupLayout.PREFERRED_SIZE)));

    btnOk.setText("OK"); // NOI18N
    btnOk.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnOkActionPerformed(evt);
      }
    });

    btnTgDetails.setText("Details"); // NOI18N
    btnTgDetails.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnTgDetailsActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout
        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addGroup(
            layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE).addComponent(btnOk, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnTgDetails, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap())
        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        layout
            .createSequentialGroup()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(btnTgDetails)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addComponent(btnOk).addContainerGap()))));

    pack();
  }

  private void btnTgDetailsActionPerformed(java.awt.event.ActionEvent evt) {
    if (jPanel2.isVisible()) {
      btnTgDetails.setText("Details>>");
    } else {
      btnTgDetails.setText("Details<<");
    }
    jPanel2.setVisible(!jPanel2.isVisible());
    this.validate();
    this.pack();
  }

  private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {
    dispose();
  }

  private void jPanel2ComponentHidden(java.awt.event.ComponentEvent evt) {
    setResizable(false);
  }

  private void jPanel2ComponentShown(java.awt.event.ComponentEvent evt) {
    setResizable(true);
  }

  public static void main(String args[]) {
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException ex) {
      java.util.logging.Logger.getLogger(TestHide.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
      java.util.logging.Logger.getLogger(TestHide.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      java.util.logging.Logger.getLogger(TestHide.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(TestHide.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    showMessageDialog(null, "I am title", "Small message...", "long\n\nlong\nmessage", JOptionPane.INFORMATION_MESSAGE);
  }

  public static void showMessageDialog(Frame parent, String title, String shortMessage, String longMessage, int type) {
    TestHide md = new TestHide(parent, true);
    Icon icon = null;
    switch (type) {
    case JOptionPane.ERROR_MESSAGE:
      icon = UIManager.getIcon("OptionPane.errorIcon");
      break;
    case JOptionPane.INFORMATION_MESSAGE:
      icon = UIManager.getIcon("OptionPane.informationIcon");
      break;
    case JOptionPane.WARNING_MESSAGE:
      icon = UIManager.getIcon("OptionPane.warningIcon");
      break;
    }

    md.setTitle(title);
    md.lblIcon.setIcon(icon);
    md.taShortMsg.setText(shortMessage);
    if (longMessage == null) {
      md.btnTgDetails.setVisible(false);
    } else {
      md.taDetails.setText(longMessage);
      md.taDetails.setCaretPosition(0);
    }
    md.pack();
    md.setVisible(true);
  }

  private javax.swing.JButton btnOk;
  private javax.swing.JToggleButton btnTgDetails;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JPanel jPanel3;
  private javax.swing.JPanel jPanel4;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JSeparator jSeparator1;
  private javax.swing.JSeparator jSeparator2;
  private javax.swing.JSeparator jSeparator3;
  private javax.swing.JLabel lblIcon;
  private javax.swing.JTextArea taDetails;
  private javax.swing.JTextArea taShortMsg;
}
  • 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-30T11:41:42+00:00Added an answer on May 30, 2026 at 11:41 am

    If you put the following statement in a constructor like

    public TestHide(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    setIconImage(Toolkit.getDefaultToolkit().getImage("images\\white_title.png"));
    initComponents();
    jPanel2.setVisible(false);
    pack();  }
    

    then the icon on title bar appear constantly.

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

Sidebar

Related Questions

EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
I have a question concerning volatile keyword I can't seem to find an answer
This is my first question that I haven't been able to find an answer
Sorry if this question may be simple, but I can't seem to find an
EDIT: Now a Major Motion Blog Post at http://messymatters.com/sealedbids The idea of rot13 is
EDIT: There's now a doc page on this so this question is irrelevant, also
EDIT following Ben's answer I'm trying to make something that should be very easy
After having an answer here wrong, because I wasn't up to date on the
I tried to find solution by google and here in SO but couldn't found...

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.