Programmatically Making the Selected OutlineView Cell Editable
Posted
by Geertjan
on Oracle Blogs
See other posts from Oracle Blogs
or by Geertjan
Published on Mon, 2 Apr 2012 20:59:10 -0500
Indexed on
2012/04/03
5:35 UTC
Read the original article
Hit count: 300
/NetBeans IDE
When you're using the OutlineView and you use the Tab key to move through its cells, the cells are shown to be selected, as below:
However, until you press the Space key in the selected cell, or until you click the mouse within it, you cannot edit it.
That's extremely annoying when you're creating a data-entry application. Your user would like to begin editing a cell as soon as they have tabbed into it. Needing to press Space first, or click the mouse in the cell first, is a cumbersome additional step that completely destroys your work flow. Below, you can see that an editable cell looks very different to one that is merely selected:
I.e., now I can type and the text changes. How to set up the OutlineView so that the Tab key makes the selected cell editable? Here's the constructor of the TopComponent you see above:
public ViewerTopComponent() { initComponents(); setName(Bundle.CTL_ViewerTopComponent()); setToolTipText(Bundle.HINT_ViewerTopComponent()); setLayout(new BorderLayout()); OutlineView ov = new OutlineView(); final Outline outline = ov.getOutline(); outline.setRootVisible(false); //When column selection changes, e.g., via Tab key, //programmatically start editing the cell: ListSelectionListener listSelectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int row = outline.getSelectedRow(); int column = outline.getSelectedColumn(); //Ignore the node column: if (row > -1 && row > -1) { outline.editCellAt(row, column); } } }; outline.getColumnModel().getSelectionModel().addListSelectionListener(listSelectionListener); ov.setPropertyColumns( "city", "City", "state", "State"); add(ov, BorderLayout.CENTER); em.setRootContext( new AbstractNode(Children.create(new CustomerChildFactory(), true))); associateLookup(ExplorerUtils.createLookup(em, getActionMap())); }
© Oracle Blogs or respective owner