@@ -723,6 +723,21 @@ protected void setJ2sMouseHandler() {
723723 J2S .setMouse (domNode , true );
724724 }
725725
726+ /**
727+ * fired by JSComponent when key listeners are registered
728+ *
729+ * @param on
730+ */
731+ public void enableJSKeys (boolean on ) {
732+ if (!on ) {
733+ setTabIndex (-1 );
734+ } else if (keysEnabled ) {
735+ setTabIndex (0 );
736+ } else {
737+ setJ2SKeyHandler ();
738+ }
739+ }
740+
726741 protected void setJ2SKeyHandler () {
727742 keysEnabled = true ;
728743 if (focusNode == null )
@@ -734,7 +749,11 @@ protected void setJ2SKeyHandler() {
734749 }
735750
736751 protected void setTabIndex (int i ) {
737- if (focusNode != null )
752+ if (focusNode == null )
753+ return ;
754+ if (i < 0 )
755+ focusNode .removeAttribute ("tabindex" );
756+ else
738757 focusNode .setAttribute ("tabindex" , "" + i );
739758 }
740759
@@ -1128,17 +1147,11 @@ public DOMNode updateDOMNode() {
11281147 }
11291148
11301149 protected DOMNode updateDOMNodeCUI () {
1131- if (cellComponent != null ) {
1132- updateCell (cellWidth , cellHeight );
1133- }
1134-
1135- if (!keysEnabled && jc .eventTypeEnabled (KeyEvent .KEY_PRESSED )) {
1136- setJ2SKeyHandler ();
1137- }
1150+ if (cellComponent != null )
1151+ updateCell (cellWidth , cellHeight );
11381152 return domNode ;
11391153 }
11401154
1141-
11421155 private void updateCell (int width , int height ) {
11431156 DOMNode .setStyles (domNode , "width" , "100%" , "height" , "100%" );
11441157 if (allowPaintedBackground )
@@ -2125,9 +2138,9 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
21252138 boolean ltr = jc .getComponentOrientation ().isLeftToRight ();
21262139 boolean alignLeft , alignRight , alignHCenter , textRight ;
21272140 if (menuAnchorNode == null ) {
2128- alignLeft = (hAlign == SwingConstants .LEFT
2141+ alignLeft = (w == 0 || hAlign == SwingConstants .LEFT
21292142 || hAlign == (ltr ? SwingConstants .LEADING : SwingConstants .TRAILING ));
2130- alignRight = (hAlign == SwingConstants .RIGHT
2143+ alignRight = w != 0 && (hAlign == SwingConstants .RIGHT
21312144 || hAlign == (ltr ? SwingConstants .TRAILING : SwingConstants .LEADING ));
21322145 alignHCenter = (!alignLeft && !alignRight );
21332146 textRight = (hTextPos == SwingConstants .RIGHT
0 commit comments