-
Bug
-
Resolution: Fixed
-
P2
-
1.3.0
-
beta
-
x86
-
windows_95
Name: rmT116609 Date: 01/12/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
When having a non editable JComboBox with selectedItem(null) and step on it
with TAB in Windows Look And Feel no visible information is there to see if
it's focused or not.
The problem is in
BasicComboBoxUI.paintCurrentValue(...) returns if selectedIndex == -1.
So focus or not does not differ the view for the user.
The Motif (shows border) and Metal (button only) looks fine.
Following sample will switch to WindowsLookAndFeel and display a JComboBox and
a JTextField. Pressing TAB will show a Cursor in the JTextField but nothing in
the JComboBox.
package com.retail_sc.javasoft.focuscombobox;
import javax.swing.*;
import com.sun.java.swing.plaf.windows.*;
/**
* Sample showing the small JComboBox in Jdk 1.3
* Switch to another Look And Feel using the class Name of it as first parameter
*
* Creation date: (04.01.01 09:57:35)
* @author: Stefan Cordes
*/
public class FocusComboBoxTest extends JFrame {
private JComboBox ivjJComboBox1 = null;
private JPanel ivjJFrameContentPane = null;
private JTextField ivjJTextField1 = null;
private JLabel ivjJLabel1 = null;
/**
* WindowsComboBoxUITest constructor comment.
*/
public FocusComboBoxTest() {
super();
initialize();
}
/**
* WindowsComboBoxUITest constructor comment.
* @param title java.lang.String
*/
public FocusComboBoxTest(String title) {
super(title);
}
/**
* Return the JComboBox1 property value.
* @return javax.swing.JComboBox
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JComboBox getJComboBox1() {
if (ivjJComboBox1 == null) {
try {
ivjJComboBox1 = new javax.swing.JComboBox();
ivjJComboBox1.setName("JComboBox1");
ivjJComboBox1.setEditable(false);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJComboBox1;
}
/**
* Return the JFrameContentPane property value.
* @return javax.swing.JPanel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJFrameContentPane() {
if (ivjJFrameContentPane == null) {
try {
ivjJFrameContentPane = new javax.swing.JPanel();
ivjJFrameContentPane.setName("JFrameContentPane");
ivjJFrameContentPane.setLayout(new java.awt.GridBagLayout());
ivjJFrameContentPane.setBackground(java.awt.SystemColor.controlHighlight);
java.awt.GridBagConstraints constraintsJTextField1 =new java.awt.GridBagConstraints();
constraintsJTextField1.gridx = 1;
constraintsJTextField1.gridy = 1;
constraintsJTextField1.fill = java.awt.GridBagConstraints.HORIZONTAL;
constraintsJTextField1.weightx = 1.0;
constraintsJTextField1.insets = new java.awt.Insets(4,4, 4, 4);
getJFrameContentPane().add(getJTextField1(),
constraintsJTextField1);
java.awt.GridBagConstraints constraintsJComboBox1 = new java.awt.GridBagConstraints();
constraintsJComboBox1.gridx = 0;
constraintsJComboBox1.gridy = 1;
constraintsJComboBox1.fill = java.awt.GridBagConstraints.HORIZONTAL;
constraintsJComboBox1.weightx = 1.0;
constraintsJComboBox1.insets = new java.awt.Insets(4,4, 4, 4);
getJFrameContentPane().add(getJComboBox1(),
constraintsJComboBox1);
java.awt.GridBagConstraints constraintsJLabel1 = new java.awt.GridBagConstraints();
constraintsJLabel1.gridx = 0; constraintsJLabel1.gridy= 0;
constraintsJLabel1.insets = new java.awt.Insets(4, 4, 4, 4);
getJFrameContentPane().add(getJLabel1(),constraintsJLabel1);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJFrameContentPane;
}
/**
* Return the JLabel1 property value.
* @return javax.swing.JLabel
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JLabel getJLabel1() {
if (ivjJLabel1 == null) {
try {
ivjJLabel1 = new javax.swing.JLabel();
ivjJLabel1.setName("JLabel1");
ivjJLabel1.setText("Non Editable JComboBox");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJLabel1;
}
/**
* Return the JTextField1 property value.
* @return javax.swing.JTextField
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JTextField getJTextField1() {
if (ivjJTextField1 == null) {
try {
ivjJTextField1 = new javax.swing.JTextField();
ivjJTextField1.setName("JTextField1");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJTextField1;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(java.lang.Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout
*/
System.out.println("--------- UNCAUGHT EXCEPTION ---------");
exception.printStackTrace(System.out);
}
/**
* Initialize the class.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("WindowsComboBoxUITest");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setSize(426, 240);
setContentPane(getJFrameContentPane());
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
// user code begin {2}
initModel();
// user code end
}
/**
* Insert the method's description here.
* Creation date: (04.01.01 10:00:37)
*/
protected void initModel() {
DefaultComboBoxModel tempModel;
tempModel = new DefaultComboBoxModel();
tempModel.addElement("TEST");
getJComboBox1().setModel(tempModel);
getJComboBox1().setSelectedItem(null);
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
// Set the Look and Feel to Windows
if ((args != null) && (args.length == 1)) {
UIManager.setLookAndFeel(args[0]);
} else {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
}
//
FocusComboBoxTest aFocusComboBoxTest;
aFocusComboBoxTest = new FocusComboBoxTest();
aFocusComboBoxTest.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e)
{
System.exit(0);
};
});
aFocusComboBoxTest.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of javax.swing.JFrame");
exception.printStackTrace(System.out);
}
}
}
(Review ID: 115065)
======================================================================