Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4164757
Votes 0
Synopsis setDefaultButton() is Broken for JInternalFrame
Category java:classes_swing
Reported Against 1.1.6
Release Fixed
State 11-Closed, duplicate of 4146858, bug
Priority: 4-Low
Related Bugs 4146858
Submit Date 07-AUG-1998
Description
The test case below fails for both Solaris and Windows.  The JDK is 1.1.6, the 
Swing version 1.0.2.

When the application is initialized, the default button Button2 displays and 
functions properly.  However, when the user tabs to Button1, Button1 is erroneously highlighted and acts as the default button (it is activated when
the return key is pressed).  Button1 continues to act as the default button when tabbing to field2.  When tabbing to Button2, Button2 again acts as the default button.

--------------------------------- UnDefaultify.java ----------------------------

import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;


public class UnDefaultify extends JInternalFrame {

  public UnDefaultify() {
    setSize(200, 200);
    setResizable(true);
    createComps();
    removeEnterMapping();
    layoutComps();
    getRootPane().setDefaultButton(button2);
  }


  protected void createComps() {
    field1 = new JTextField("field 1");
    field2 = new JTextField("field 2");
    button1=  new JButton("Button 1");
    button2=  new JButton("Button 2 (DEF)");
    combo1 = new JComboBox();
  }

  protected void layoutComps() {
    GridBagConstraints f1GBC = createGBConstraints(0, 0, 1, 1,
    GridBagConstraints.NONE,
    GridBagConstraints.CENTER,
    1.0, 1.0);
    GridBagConstraints b1GBC = createGBConstraints(1, 0, 1, 1,
    GridBagConstraints.NONE,
    GridBagConstraints.CENTER,
    1.0, 1.0);

    GridBagConstraints f2GBC = createGBConstraints(0, 1, 1, 1,
    GridBagConstraints.NONE,
    GridBagConstraints.CENTER,
    1.0, 1.0);

    GridBagConstraints b2GBC = createGBConstraints(1, 1, 1, 1,
    GridBagConstraints.NONE,
    GridBagConstraints.CENTER,
    1.0, 1.0);

    GridBagConstraints c1GBC = createGBConstraints(0, 2, 2, 1,
    GridBagConstraints.NONE,
    GridBagConstraints.CENTER,
    1.0, 1.0);

    getContentPane().setLayout(new GridBagLayout());
    getContentPane().add(field1, f1GBC);
    getContentPane().add(button1, b1GBC);
    getContentPane().add(field2,f2GBC);
    getContentPane().add(button2, b2GBC);
    getContentPane().add(combo1, c1GBC);
  }

  protected void removeEnterMapping() {
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    field1.getKeymap().removeKeyStrokeBinding(enter);
    field2.getKeymap().removeKeyStrokeBinding(enter);
  }

  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      System.out.println("Could not set L&F: " + e);
      e.printStackTrace();
    }
    JFrame frame = new JFrame();
    frame.setSize(400, 400);
    JDesktopPane dt = new JDesktopPane();
    frame.getContentPane().add(dt);
    frame.setVisible(true);
    UnDefaultify tt = new UnDefaultify();
    dt.add(tt);
  }


  JTextField field1;
  JTextField field2;
  JComboBox combo1;
  JButton button1;
  JButton button2;


  public static GridBagConstraints
  createGBConstraints(int gridx, int gridy, int gridwidth,
        int gridheight, int fill, int anchor,
        double weightx, double weighty) {
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = gridx;
    gbc.gridy = gridy;
    gbc.gridwidth = gridwidth;
    gbc.gridheight = gridheight;
    gbc.fill = fill;
    gbc.anchor = anchor;
    gbc.weightx = weightx;
    gbc.weighty = weighty;
    return gbc;
  }
}
Work Around
N/A
Evaluation
It's true.  For the Motif LAF, the "default" should follow the *button*
with focus, but when focus leaves the button for a non-button, the original
default should be restored.

This is a problem in both Motif & Windows look and feel, and is really
a duplicate of 4146858.

  xxxxx@xxxxx   1998-12-11
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang