Я создаю Jtree с корневым узлом, а затем создаю еще один поток, который асинхронно обновляет корневой узел.
Это работает фантастически, если я запускаю это Jtree независимо в какой-либо JPanel, оно даже работало в каком-то месте проекта, но меня попросили добавить это Jtree в какой-то новый компонент Swing.
В новой панели Swing он не заполняется полностью, он заполняет только те узлы, которые были вставлены (при запуске в течение нескольких миллисекунд) до того, как Jtree было отображено на экране. После рендеринга Jtree он не обновляется. Теперь интересная часть. Я также сделал прослушиватель мыши на узле, чтобы я мог создать новый узел, щелкнув правой кнопкой мыши функцию создания узла, и с этим новым узлом создается и добавляется в корневой узел Jtree.
Важно добавить, что я использовал метод newThread(){void run}).start() для создания потока для добавления узла в Jtree, потому что раньше я никогда не чувствовал необходимости в методе SwingUtilities.invokeLater. но теперь, если я использовал метод SwingUtilities.invokeLater, то главное окно также не открывается, оно просто останавливается во время запуска, я только что проверил, что SwingUtilities.invokeLater также отлично работает со старым компонентом и, конечно же, отлично работает независимо.
И я вызываю model.nodeStructureChanged(changedNode); после добавления узла, поэтому раньше он работал нормально.
Пожалуйста, помогите, код трудно извлечь, и код Jtree раньше работал нормально, может быть, какой-то компонент блокирует содержащие виджеты для асинхронного обновления?
EDIT Обновите, чтобы включить некоторый код, я использую класс Temp, предоставленный Ником: -
public BasicGraphEditor(String appTitle, mxGraphComponent component)
{
// Stores and updates the frame title
this.appTitle = appTitle;
// Stores a reference to the graph and creates the command history
graphComponent = component;
final mxGraph graph = graphComponent.getGraph();
undoManager = createUndoManager();
// Do not change the scale and translation after files have been loaded
graph.setResetViewOnRootChange(false);
// Updates the modified flag if the graph model changes
graph.getModel().addListener(mxEvent.CHANGE, changeTracker);
// Adds the command history to the model and view
graph.getModel().addListener(mxEvent.UNDO, undoHandler);
graph.getView().addListener(mxEvent.UNDO, undoHandler);
// Keeps the selection in sync with the command history
mxIEventListener undoHandler = new mxIEventListener()
{
@Override
public void invoke(Object source, mxEventObject evt)
{
List<mxUndoableChange> changes = ((mxUndoableEdit) evt
.getProperty("edit")).getChanges();
graph.setSelectionCells(graph
.getSelectionCellsForChanges(changes));
}
};
undoManager.addListener(mxEvent.UNDO, undoHandler);
undoManager.addListener(mxEvent.REDO, undoHandler);
// Creates the graph outline component
graphOutline = new mxGraphOutline(graphComponent);
// Creates the library pane that contains the tabs with the palettes
libraryPane = new JTabbedPane();
/////////////////////////////////////////////////
// Only change i have done here: start
////////////////////////////////////////////////
Temp tempExplorer = new Temp();
libraryPane.add("new Explorere", tempExplorer);
/////////////////////////////////////////////////
// Only change i have done here: End
////////////////////////////////////////////////
// Creates the inner split pane that contains the library with the
// palettes and the graph outline on the left side of the window
JSplitPane inner = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
libraryPane, graphOutline);
inner.setDividerLocation(320);
inner.setResizeWeight(1);
inner.setDividerSize(6);
inner.setBorder(null);
// Creates the outer split pane that contains the inner split pane and
// the graph component on the right side of the window
JSplitPane outer = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, inner,
graphComponent);
outer.setOneTouchExpandable(true);
outer.setDividerLocation(200);
outer.setDividerSize(6);
outer.setBorder(null);
// Creates the status bar
statusBar = createStatusBar();
// Display some useful information about repaint events
installRepaintListener();
// Puts everything together
setLayout(new BorderLayout());
add(outer, BorderLayout.CENTER);
add(statusBar, BorderLayout.SOUTH);
installToolBar();
// Installs rubberband selection and handling for some special
// keystrokes such as F2, Control-C, -V, X, A etc.
installHandlers();
installListeners();
updateTitle();
}
Приведенный выше класс взят из библиотеки Jgraph как https://github.com/jgraph/jgraphx. И я просто добавление компонента jtree, как указано выше, никаких других изменений. пожалуйста помоги.