在我正在开展的一个项目中,我们决定改变一些数据的呈现方式。现在我们正在使用Netbeans ListView,到目前为止效果很好。但是现在我们想要改变/扩展ListView以像手风琴一样工作。我们可以将ListView扩展为看起来像手风琴,但如果我们向每个单元格/行添加按钮或文本输入,我们就无法将actionListener附加到该按钮。似乎ListView侦听器始终位于swing组件之上。
有没有人对如何使用Netbeans Explorer API创建手风琴有任何建议?
我们可以创建自定义Swing组件,就像那样,实际上Web上已存在一个。如果我们创建一个,我们需要将Lookup与我们的自定义Swing组件连接,以便与Netbeans API一起正常工作。我们希望只有在没有其他选择时才这样做。 使用Netbeans API搜索此类组件并未提供任何有用的结果。
答案 0 :(得分:4)
请注意:
代码示例
public class TaskPaneView extends JScrollPane {
private transient ExplorerManager manager;
// create a taskpanecontainer
JXTaskPaneContainer taskpanecontainer = new JXTaskPaneContainer();
/** Listener to nearly everything */
transient Listener managerListener;
/** weak variation of the listener for property change on the explorer manager */
transient PropertyChangeListener wlpc;
/** True, if the selection listener is attached. */
transient boolean listenerActive;
// UI Settings:
Font labelFont = new Font("Segoe UI", Font.BOLD, 14);
Painter backgroundPainter = new MattePainter(Color.white);
public TaskPaneView() {
setViewportView(taskpanecontainer);
}
public void setBackground(Painter background) {
this.backgroundPainter = background;
}
public void setLabelFont(Font labelFont) {
this.labelFont = labelFont;
}
@Override
public void addNotify() {
super.addNotify();
ExplorerManager em = ExplorerManager.find(this);
if (em != manager) {
if (manager != null) {
manager.removePropertyChangeListener(wlpc);
}
manager = em;
manager.addPropertyChangeListener(wlpc = WeakListeners.propertyChange(managerListener, manager));
Node root = manager.getExploredContext();
setRootNode(root);
} else {
// bugfix #23509, the listener were removed --> add it again
if (!listenerActive && (manager != null)) {
manager.addPropertyChangeListener(wlpc = WeakListeners.propertyChange(managerListener, manager));
}
}
}
/** Removes listeners.
*/
@Override
public void removeNotify() {
super.removeNotify();
listenerActive = false;
// bugfix #23509, remove useless listeners
if (manager != null) {
manager.removePropertyChangeListener(wlpc);
}
}
private void setRootNode(Node root) {
//throw new UnsupportedOperationException("Not yet implemented");
taskpanecontainer.removeAll();
System.out.println("root node set " + root);
Node[] children = root.getChildren().getNodes();
for (int i = 0; i < children.length; i++) {
Node node = children[i];
JXTaskPane taskPane = new JXTaskPane();
taskPane.setName(node.getName());
taskPane.setCollapsed(true);
taskPane.setTitle(node.getDisplayName());
taskPane.setIcon(new ImageIcon(node.getIcon(BeanInfo.ICON_COLOR_16x16)));
Action [] actions = node.getActions(true);
for (int j = 0; j < actions.length; j++) {
Action action = actions[j];
taskPane.add(action);
}
taskpanecontainer.add(taskPane);
}
}
private final class Listener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent evt) {
if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) {
setRootNode(manager.getExploredContext());
return;
}
}
}
}
答案 1 :(得分:3)
答案 2 :(得分:2)