armin
armin

Reputation: 2025

How to set JInternalFrame title?

I'm trying to set the title bar of JInternalFrame with setTitle() but it does not change.I don't know what am I doing wrong? I works fine if I initialize it in the constructor,but after it is set,it does not change.

Here is my code :

JInternalFrame internalFrame = new JInternalFrame("test",false, false, false, false);
internalFrame.setTitle("test2");

this is the result I'm getting.

enter image description here

Upvotes: 1

Views: 1924

Answers (2)

AJ.
AJ.

Reputation: 4534

JDK-4131008 : JInternalFrame doesn't refresh after changing the title, you must call repaint()

Upvotes: 2

splungebob
splungebob

Reputation: 5415

It works for me:

import javax.swing.*;

public class JInternalFrameDemo implements Runnable
{
  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(new JInternalFrameDemo());
  }

  public void run()
  {
    JInternalFrame iFrame = new JInternalFrame("Test 1",
                                               false, false, false, false);
    iFrame.setTitle("Test 2");
    iFrame.setSize(200, 150);
    iFrame.setLocation(10, 10);
    iFrame.setVisible(true);

    JDesktopPane desktop = new JDesktopPane();
    desktop.setOpaque(true);
    desktop.add(iFrame);

    JFrame frame = new JFrame("Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 300);
    frame.setContentPane(desktop);
    frame.setVisible(true);
  }
}

Upvotes: 0

Related Questions