-
Explorer type GUI interface
I have been writing an "explorer" type gui interface. The left pane in a
split pane is a tree and the right is a panel with field elements when a
leaf is selected. I have been trying to modify a class that represents my
model (my model is separate and distinct from the data store engine) to update
the leaf when I change the name in the panel. The first field name represents
the leaf name on the tree. I am trying to change this when the enter key
is hit in the panel. However I can not seem to fire the right tree event
to update the leaf name. Currently, the node name change is only reflected
when I select the leaf again for display, so I thought I could force an update
with an event...
code:
newNode()
{
...
DefaultMutableTreeNode lastNode =
(DefaultMutableTreeNode)m_jTreePath.getLastPathComponent();
DefaultMutableTreeNode parent;
DefaultMutableTreeNode node = new DefaultMutableTreeNode();
parent = (DefaultMutableTreeNode)lastNode.getRoot();
int index = parent.getIndex(jRootNode)+1;
m_count++;
// this is the name of the leaf to be changed later by the user
String propertyName = "Untitled" + m_count;
// add to collection with developer type as key
ConfigProperty prop =
addNodeToTree(propertyName, "Developer");
prop.devProp.setPropertyName(propertyName);
prop.setDevProp();
node.setUserObject(prop);
// put it in the tree
jTreeModel.insertNodeInto(node, parent, index);
// display it in the right panel
m_jSplitPane.setRightComponent(prop.devProp);
...
}
public class Property_Dev extends JPanel implements ActionListener
{
...
JTextField jPropNameField = new JTextField();
...
public void setPropertyName(String propName)
{
jPropNameField.addKeyListener(new propNameFieldListener());
jPropNameField.setText(propName);
}
...
class propNameFieldListener extends KeyAdapter
{
public void keyTyped(KeyEvent kev)
{
char c = kev.getKeyChar();
if(c == KeyEvent.VK_ENTER)
{
// Fire the tree event here to update the leaf (node) display on
the tree
}
}
}
I am not even sure if this is the most efficient way to implement this.
It seems that this might be very slow and burden the system for handling
events in the text field. Should the listener be removed after setting the
property name? Or should this be implemented in a whole different manner?
Hope someone can help. Thanks in advance
-
Re: Explorer type GUI interface
I have a lot of panels that are very much like this, where I can change a
leaf name in the tree from the panel. The way I seem to have solved that
problem (I vaguely recall, it having been several months ago), was to use a
TreeCellRenderer to format the leaf names. Even that didn't update the leaf
name until I included a call to "invalidate()" in my renderer. Here's one
of my renderers:
package Taxonomy;
import BNBUtil.*;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;
import java.awt.Color;
import java.awt.Component;
public class TaxonomicTreeRenderer extends JLabel implements
TreeCellRenderer
{
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded,
boolean leaf, int row, boolean hasFocus) {
TaxonomicTreeNode node = (TaxonomicTreeNode)value;
Taxonomic txc = node.getTaxonomic();
setText(txc.toString());
setFont(BNBUtil.plainFont);
if (selected)
setForeground(Color.red);
else
setForeground(Color.black);
invalidate();
return this;
}
}
Dave Miller <dmiller@euronetservices.com> wrote in message
news:3a114778$1@news.devx.com...
>
> I have been writing an "explorer" type gui interface. The left pane in a
> split pane is a tree and the right is a panel with field elements when a
> leaf is selected. I have been trying to modify a class that represents my
> model (my model is separate and distinct from the data store engine) to
update
> the leaf when I change the name in the panel. The first field name
represents
> the leaf name on the tree. I am trying to change this when the enter key
> is hit in the panel. However I can not seem to fire the right tree event
> to update the leaf name. Currently, the node name change is only
reflected
> when I select the leaf again for display, so I thought I could force an
update
> with an event...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks