Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [albireo-dev] Initial scrolling of Swing text fields

Gordon Hirsch wrote:

Then I tried it in a separate view (TextFieldsView, committed). Again
two under-sized text fields. But here, with or without your addition,
the second text field is not scrolled. Even after tabbing through the text
fields, it is not scrolled.

I'll look into this.

My attempts to force the scroll by re-setting the caret position were, in some cases, being optimized away. I've changed the code, and proper scrolling occurs with the TextFieldsView on both Windows and Gtk.

There also seems to be a separate problem with tab traversals on the TextFieldsView which I will investigate.
### Eclipse Workspace Patch 1.0
#P org.eclipse.albireo.core
Index: src/org/eclipse/albireo/core/SwingControl.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.core/src/org/eclipse/albireo/core/SwingControl.java,v
retrieving revision 1.64
diff -u -r1.64 SwingControl.java
--- src/org/eclipse/albireo/core/SwingControl.java	21 Apr 2008 22:44:43 -0000	1.64
+++ src/org/eclipse/albireo/core/SwingControl.java	22 Apr 2008 17:24:14 -0000
@@ -1308,8 +1308,14 @@
     protected void scrollTextFields(Component c) {
         if (c instanceof JTextComponent) {
             JTextComponent tc = (JTextComponent)c;
-            // This scrolls the text component to the proper place
-            tc.setCaretPosition(tc.getCaretPosition());
+            if (tc.getText().length() > 0) {
+                // Reset the caret position to force a scroll of 
+                // the text component to the proper place
+                int position = tc.getCaretPosition();
+                int tempPosition = (position > 0) ? 0 : 1; 
+                tc.setCaretPosition(tempPosition);
+                tc.setCaretPosition(position);
+            }
         } else if (c instanceof Container) {
             Component[] children = ((Container)c).getComponents();
             for (int i = 0; i < children.length; i++) {

Back to the top