Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4120856

win32: setTitle on modal dialogs will fail to change the title



    • Subcomponent:
    • Resolved In Build:
    • CPU:
      generic, x86
    • OS:
      solaris_10, windows_95, windows_nt
    • Verification:
      Not verified


      On win32, changing the title of a modal dialog doesn't appear to work.

      The included program demonstrates this problem.
      Bring up the program
      Click on "Show Modal Dialog"
      (note the dialog title: "New Title: 1")
      Click on "Close Modal Dialog"

      Click on "Show Modal Dialog" again
      (note the dialog title is STILL "New Title: 1", should be "New Title: 2")

      The problem only occurs with modal dialogs (setTitle on non-modal Dialogs
      and Frames works fine), and it only occurs on win32.

      Also, strangely enough, if you call setTitle *while* the modal dialog
      is showing, it works!

      Unfortunately, though, this bug affects Swing because for our Option dialogs,
      we re-use dialog instances (to get around a bug in Solaris where disposing
      dialogs causes a SEGV), and this bug causes titles to be incorrect.

      import java.awt.*;
      import java.awt.event.*;

      public class WinTitleTest extends Frame {
          Dialog dialog, modalDialog;
          Frame frame;

          public WinTitleTest() {
              super("Window Title Test");

              add("North", new Label("Window titles should change each time shown..."));
              Panel p = new Panel();
              p.setLayout(new FlowLayout());
              add("Center", p);

              modalDialog = new Dialog(this, "Initial Title", true);
              Button b = new Button(" Close Modal Dialog... ");
              b.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
              modalDialog.add("North", b);
              b = new Button("Show Modal Dialog");
              b.addActionListener(new TitleChanger(modalDialog));

              dialog = new Dialog(this, "Initial Title", false);
              b = new Button(" Close Dialog... ");
              b.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
              dialog.add("North", b);
              b = new Button("Show Dialog");
              b.addActionListener(new TitleChanger(dialog));

              frame = new Frame("Initial Title");
              b = new Button(" Close Frame.... ");
              b.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
              frame.add("North", b);

              b = new Button("Show Frame");
              b.addActionListener(new TitleChanger(frame));

          public static void main(String[] args) {
              WinTitleTest test = new WinTitleTest();

      class TitleChanger implements ActionListener {
          Window win;
          int counter = 0;

          public TitleChanger(Window win) {
              this.win = win;

          public void actionPerformed(ActionEvent e) {
              if (win instanceof Frame) {
                  ((Frame)win).setTitle("New Title: "+(++counter));
              } else if (win instanceof Dialog) {
                  // BUG: This seems to fail for modal dialogs!!!!
                  ((Dialog)win).setTitle("New Title: "+(++counter));

      erik.larsen@Eng 1998-05-21
      web bug Incident: (###@###.###)
      import java.awt.*;
      import java.awt.event.*;

      public class DialogTest extends java.awt.Frame {
      public static void main( String[] args ) {
      final Frame dt = new DialogTest();
      dt.setVisible( true );

      final Dialog d = new Dialog( dt, "", true );
      WindowListener l = new WindowAdapter() {
      public void windowClosing(WindowEvent e){
      if ( e.getSource() == dt ) System.exit(0);
      System.out.println( "setting title to \"TITLE 1\"" );
      d.setTitle( "TITLE 1" );
      dt.addWindowListener( l );
      d.addWindowListener( l );
      d.setBounds( 5,5,200,50 );
      d.setVisible( true );
      System.out.println( "setting title to \"TITLE 2\"" );


          Issue Links



              lbunnisunw Lara Bunni (Inactive)
              amfowler Anne Fowler (Inactive)
              0 Vote for this issue
              0 Start watching this issue