Skip to content

Commit 7daec02

Browse files
hansonrhansonr
authored andcommitted
corrects problem that checkbox may have to be set enabled before
changing its state and having the HTML5 input element track properly -- missing ButtonListener.verifyButtonClick, but probably better to have that bypassed if state is changed programmatically.
1 parent 18a279f commit 7daec02

File tree

8 files changed

+13
-11
lines changed

8 files changed

+13
-11
lines changed
212 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190702213116
1+
20190703083607
212 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190702213116
1+
20190703083607
212 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/swingjs/plaf/ButtonListener.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ public void mouseExited(MouseEvent e) {
329329
}
330330

331331
/**
332-
* Just ensure the button is in sync by forcing the HTML5 DOM button to the same
333-
* setting as Java.
332+
* It is necessary that this method be called any time the "CHECKED" attribute
333+
* of a toggle button is changed. Otherwise it may fire for a previous state
334+
* after the state is changed in code directly.
334335
*
335336
* @param m
336337
*
@@ -339,12 +340,13 @@ public void mouseExited(MouseEvent e) {
339340
boolean verifyButtonClick(AbstractButton b) {
340341
ButtonModel m = b.getModel();
341342
DOMNode btn = ui.actionNode;
342-
// BH: I don't know that this is necessary anymore
343-
boolean state = m.isSelected();// && !ui.isRadio;
343+
boolean state = m.isSelected();
344344
/**
345345
* @j2sNative
346346
*
347-
* setTimeout(function(){btn && (btn.checked = state)}, 0);
347+
* setTimeout(function(){
348+
* btn && btn.checked != state && (btn.checked = state);
349+
* }, 0);
348350
*/
349351
{
350352
System.out.println("" + btn + state);

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,7 @@ protected DOMNode setCssFont(DOMNode obj, Font font) {
15061506
"font-weight", ((istyle & Font.BOLD) == 0 ? "normal" : "bold"));
15071507
}
15081508

1509+
// force the issue
15091510
enabled = !c.isEnabled();
15101511
setEnabled(c.isEnabled());
15111512
return obj;
@@ -2110,7 +2111,7 @@ protected void enableNode(DOMNode node, boolean b) {
21102111
if (node == null)
21112112
return;
21122113

2113-
DOMNode.setAttr(node, "disabled", (b ? null : TRUE));
2114+
DOMNode.setAttr(node, "disabled", (b ? FALSE : TRUE));
21142115
if (!b && inactiveForeground == colorUNKNOWN)
21152116
getDisabledColors(buttonNode == null ? getPropertyPrefix() : "Button");
21162117
if (jc.isOpaque()) {

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSRadioButtonUI.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
7777

7878
protected void setupButton(JToggleButton b, boolean doAll) {
7979
// actionNode, iconNode, textNode, centeringNode, buttonNode
80-
81-
DOMNode.setAttr(actionNode, "checked", b.isSelected() ? TRUE : null);
82-
80+
DOMNode.setAttr(actionNode, "checked", b.isSelected() ? TRUE : FALSE);
81+
buttonListener.verifyButtonClick(b); // necessary!
8382
setCssFont(textNode, c.getFont());
8483
// TODO: not allowing radio/checkbox icons (custom buttons)
8584
setIconAndText("radio", (ImageIcon) null/* button.getIcon() */, button.getIconTextGap(), button.getText());

0 commit comments

Comments
 (0)