Hi Prashanth,

To tab out of a table, you could use CTRL-Tab to go to the next focusable 
component. Is this not an acceptable solution? 

If not, then as Robert mentioned in an earlier mail, you will need to extend 
ULCTable on the client side.

Please see the snippet at the end of this mail.

BTW, could you please tell us:
- what kind of application are you developing?
- which company are you working for?
- what kind of license are you using?

We strongly recommend that you buy support.

Thanks and regards,

Janak

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of prashanth tr
Sent: Monday, July 10, 2006 10:35 AM
To: [email protected]
Subject: [ULC-developer] cells navigation in ULCTable


Hi,

I am using ulc 6.1 version.
In our UIs we want everything to be navigatable from Keyboard alone, without 
use of mouse.
In our screen we have a table and few buttons like Select, Cancel and Clear 
Buttons.

Problem : -
Whenever  the Last cell in the table is reached by tabing each cell
the focus goes back to the first cell of the table instead of going to 
the immediate component added ( say Select Button in my case ). 

My Requiement : -
After reaching the last cell in table it should go to the immediate 
Select button which i added.( or  the next focusable comonent )

I tried with
table.setNextFocustableComponent(SelectButton); 
selectButton.requestFocus();

But it didnt work.

-- 
Thanks
Prashanth 

--------------------------------------------------------------

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCAlert;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCComponent;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCScrollPane;
import com.ulcjava.base.application.ULCTable;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.application.table.DefaultTableModel;
import com.ulcjava.base.application.table.ITableModel;
import com.ulcjava.base.client.UITable;
import com.ulcjava.base.development.DevelopmentRunner;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.InputMap;
import javax.swing.JTable;
import javax.swing.KeyStroke;

import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
import java.awt.event.KeyEvent;

public class ULCTableTabNavigationSnippet extends AbstractApplication {

    protected ULCComponent createContent() {
        ULCTable table = new MyULCTable(new DefaultTableModel(new Object[][] { 
{ 0, 0 }, { 1, 1 } }, new String[] {
                "Col1", "Col2" }));
        return new ULCScrollPane(table);
    }

    public void start() {
        ULCFrame frame = new ULCFrame("ULCTableTabNavigationSnippet");
        frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);

        ULCBoxPane content = new ULCBoxPane(true);
        
        ULCButton but1 = new ULCButton("Button1");
        content.add(ULCBoxPane.BOX_CENTER_TOP, but1);
        content.add(ULCBoxPane.BOX_EXPAND_EXPAND, createContent());

        ULCButton but2 = new ULCButton("Dialog");
        but2.addActionListener(new IActionListener() {
            public void actionPerformed(ActionEvent event) {
                new ULCAlert("Hello", "Hello", "Ok").show();
            }
        });

        content.add(ULCBoxPane.BOX_CENTER_BOTTOM, but2);
        frame.add(content);
        frame.setSize(200, 200);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        
DevelopmentRunner.setApplicationClass(ULCTableTabNavigationSnippet.class);
        DevelopmentRunner.main(args);
    }

    public static class MyULCTable extends ULCTable {
        public MyULCTable(ITableModel model) {
            super(model);
        }

        protected String typeString() {
            return MyUITable.class.getName();
        }
    }

    public static class MyUITable extends UITable {
        protected void postInitializeState() {
            super.postInitializeState();
            JTable table = getBasicTable(); 
            
            InputMap im = 
table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
            KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
            Action oldTabAction = table.getActionMap().get(im.get(tab));
            Action tabAction = new TabAction(oldTabAction);
            table.getActionMap().put(im.get(tab), tabAction);
        }

        public static class TabAction extends AbstractAction {
            private final Action fAction;
            private int lastRow = 0;
            private int lastCol = 0;
            
            public TabAction(Action action) {
                super();
                fAction = action;
            }

            public void actionPerformed(java.awt.event.ActionEvent e) {
                fAction.actionPerformed( e );
               
                JTable table = (JTable)e.getSource();
                int columnCount = table.getColumnCount();
                int rowCount = table.getRowCount();      
                int currRow = table.getSelectedRow();
                int currCol = table.getSelectedColumn();

                if (lastRow == rowCount - 1 && lastCol == columnCount - 1 && 
currRow == 0 && currCol == 0) {
                    Container cycleRoot = table.getFocusCycleRootAncestor();
                    FocusTraversalPolicy policy = 
table.getFocusTraversalPolicy();
                    if (policy == null && cycleRoot != null) {
                        policy = cycleRoot.getFocusTraversalPolicy();
                    }
        
                    Component target = policy.getComponentAfter(cycleRoot, 
table);
        
                    if (target != null)
                        target.requestFocusInWindow();
                }
        
                lastCol = currCol;
                lastRow = currRow;
            }
        }
    }
}

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to