简体   繁体   中英

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.

在此处输入图片说明

JDK-4131008:更改标题后JInternalFrame不刷新,您必须调用repaint()

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);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM