试图向JPanel添加DiffView

问题描述 投票:0回答:1

我正在开发一个基于netbeans平台的应用程序,然后重复使用diff组件。我有下一个代码:

panel = new javax.swing.JPanel();
panel.setLayout(new java.awt.BorderLayout());
DiffView view = Diff.getDefault().createDiff(original, processed);
panel.add(view.getComponent(), BorderLayout.CENTER);

但是Diff组件未添加到面板中。如果我添加另一个面板而不是Diff组件,它将起作用。同时如果我使用下一个代码:

DiffView view = Diff.getDefault().createDiff(original, processed);
TopComponent tc = new TopComponent();
tc.setDisplayName("Diff Viewer");
tc.setLayout(new BorderLayout());
tc.add(view.getComponent(), BorderLayout.CENTER);
tc.open();
tc.requestActive();

它可以工作,但是在另一个窗口中显示该组件,但不是我想要的。我的代码有什么问题,如何将Diff组件添加到面板中?谢谢。

java netbeans netbeans-platform netbeans-plugins
1个回答
0
投票

将DiffView添加到面板后,调用下面的代码来解决问题

panel.revalidate();

//or
panel.repaint();
© www.soinside.com 2019 - 2024. All rights reserved.