我知道在复选框上订阅ItemListener
可以在方法中获得ItemEvent.SELECTED/DESELECTED
状态:
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange()==ItemEvent.DESELECTED){
}
....
}
但我想知道的是"最后选择状态"在状态变化期间JComboBox实际上正在发生。当JCheckBox
扩展JToggleButton
时,必须有一些方法可以知道,因为java按钮确实有一个中间状态值,如"按下"在它真正改变到新状态之前。但是我发现在JCheckBox
答案 0 :(得分:0)
如果我将事件源转换为AbstractButton,然后执行以下操作:
<scene sceneID="PWe-2P-e7G">
<objects>
<viewController id="dVm-1J-JI9" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="AtX-Pv-6wj">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" showsVerticalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VNx-Wi-Vg6">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MqU-0Y-fM2">
<rect key="frame" x="-117" y="481" width="1000.5" height="61"/>
<mutableString key="text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</mutableString>
<fontDescription key="fontDescription" type="system" pointSize="40"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="MqU-0Y-fM2" firstAttribute="top" secondItem="VNx-Wi-Vg6" secondAttribute="top" id="rFR-UU-4Jh"/>
</constraints>
</scrollView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="VNx-Wi-Vg6" firstAttribute="height" secondItem="cuD-5b-v6o" secondAttribute="height" id="5PV-lk-7KG"/>
<constraint firstItem="VNx-Wi-Vg6" firstAttribute="width" secondItem="cuD-5b-v6o" secondAttribute="width" id="ZBA-5x-Gzn"/>
<constraint firstItem="MqU-0Y-fM2" firstAttribute="width" secondItem="cuD-5b-v6o" secondAttribute="width" id="v3U-b4-7cx"/>
</constraints>
<viewLayoutGuide key="safeArea" id="cuD-5b-v6o"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="rsr-pH-xUO" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="15.625" y="707.8125"/>
</scene>