我的组合框有问题,我无法在组合中显示数据,我必须在左键单击之前右键单击以显示我的数据,但只需左键单击它就不可能
下图显示了第一种情况(当我左键单击时)
感谢您的帮助
答案 0 :(得分:0)
/**
* Configure the renderer appropriately with the status of the
* Drawing object.
*/
public Component getListCellRendererComponent(JList list, 对象值, int索引, boolean isSelected, boolean cellHasFocus){ Component theResult = super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus); System.out.println(“theResult:”+ theResult.toString()); System.out.println(“débmethodegetLi class AWICombo => value”+ value +“,index”+ index +“,isSelected”+ isSelected +“,celhasFocus”+ cellHasFocus); //使用jdk 1.3在组合框中显示崩溃:setOpaque(true)解决了问题。 //((JComponent)theResult).setOpaque(true); // setOpaque(true); if(index == -1){ System.out.println(“如果索引== -1”); 返回结果; } 尝试{ System.out.println(“在try bloc 1”中); boolean notEmpty = false; AWCState theObjectToDisplay = null;
try {
System.out.println("In try bloc 2");
System.out.println("index " +index);
System.out.println("theModel call :" +theModel.toString());
theObjectToDisplay = (AWCState) theModel.theComboValues.elementAt( index );
System.out.println("theObjectToDisplay => "+theObjectToDisplay.toString());
System.out.println("dans conbobox "+index);
} catch ( java.lang.ArrayIndexOutOfBoundsException aioobe ) {
aioobe.printStackTrace();
}
// test if the first square of the conbo box is empty for doen't set the tool tips
if ( theObjectToDisplay != null ) {
System.out.println("In if 1");
if ( theObjectToDisplay.toString() != null ) {
System.out.println("In if 2");
if ( value.toString().compareTo( theObjectToDisplay.toString() ) != 0 ) {
System.out.println("In if 3");
if ( value.toString().compareTo( "" ) != 0 ) {
System.out.println("In if 4");
theObjectToDisplay = (AWCState) theModel.theComboValues.elementAt( index - 1 );
notEmpty = true;
}
} else {
System.out.println("In else 1");
notEmpty = true;
}
}
} else {
System.out.println("In else 2");
theObjectToDisplay = (AWCState) theModel.theComboValues.elementAt( index - 1 );
notEmpty = true;
}
if ( isSelected ) {
System.out.println("In if isSelected "+list.getSelectionBackground());
System.out.println("In if isSelected "+list.getSelectionForeground());
setBackground( list.getSelectionBackground() );
setForeground( list.getSelectionForeground() );
setToolTip( list, notEmpty, theObjectToDisplay, value );
} else {
setBackground( list.getBackground() );
setForeground( list.getForeground() );
}
setFont( list.getFont() );
if ( value == null ) {
System.out.println("In if value == null");
setText("");
}
else {
setText(value.toString());
}
// object is not obsolete
if ( theObjectToDisplay == null || theObjectToDisplay.getStatus().equals( AWCConstants.OFFICIAL ) ) {
System.out.println("object is not obsolete theObjectToDisplay=>"+theObjectToDisplay.toString());
return theResult;
}
// object is obsolete
if ( index == 1 ) {
return theResult;
}
if ( !isSelected ) {
theResult.setBackground( Color.red );
} else {
theResult.setBackground( new Color( 155, 100, 155 ) );
}
}
catch ( NullPointerException npe ) {
npe.printStackTrace();
}
catch ( java.lang.ArrayIndexOutOfBoundsException aioobe ) {
aioobe.printStackTrace();
}
System.out.println("end of function");
return theResult;
}