怎么根据JSplitPane左边的内容,比如JTree,在右边动态显示不同的JPanel,JPanel包含JLabel 和JTextField.
我用JSplitPane splitPane=new JSplitPane(JSplitPane.
HORIZONTAL_SPLIT,tree,rightpanel);
rightpanel,怎么根据需要动态的改变成panel1,panel2,panel3?
我用JSplitPane splitPane=new JSplitPane(JSplitPane.
HORIZONTAL_SPLIT,tree,rightpanel);
rightpanel,怎么根据需要动态的改变成panel1,panel2,panel3?
解决方案 »
- 请问为什么我在写入文件数据的时候会出现非法字母啊
- 这个要怎么写啊............弱弱的问
- jsp applet运行不出来
- 如何通过sax方式生成和修改XML文件?
- 请教:急!!!!!服务器端连接客户端出现异常
- JDBC连sqlserver2000问题?
- DataOutputStream使用过程中发生java.io.EOFException,不知道为啥???
- 请问我错在哪,该怎样解决这问题啊?
- JAVA数据库连接问题
- 请JAVA高手给我指一条路!!不甚感激
- 团结就是力量 我不认输 进者给分 免费放送经典的娱乐搞笑 各位兄弟姐妹 你们辛苦了 工作之余 记得休息哦
- 数据库中Calendar类型的变量要怎么在JSP页面中显示年-月-日
import java.util.HashMap;
import java.util.Map;import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;public class DynamicUITest {
public static void main(String[] args) {
JTree tree = new JTree();
JScrollPane sp = new JScrollPane(tree);
final JPanel rightPanel = new JPanel(new BorderLayout());
JSplitPane splitPane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT, sp, rightPanel);
splitPane.setDividerLocation(150);
final Map nodeCompMap = new HashMap();
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getPath();
if (path != null) {
String nodeName = path.getLastPathComponent().toString();
JComponent comp = (JComponent) nodeCompMap.get(nodeName);
if (comp == null) {
comp = createComponent(nodeName);
nodeCompMap.put(nodeName, comp);
}
rightPanel.removeAll();
rightPanel.add(comp, BorderLayout.CENTER);
rightPanel.revalidate();
rightPanel.repaint();
}
}
});
JFrame f = new JFrame("DynamicUITest");
f.getContentPane().add(splitPane, BorderLayout.CENTER);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(800, 600);
f.setLocationRelativeTo(null);
f.show();
}
private static JComponent createComponent(String nodeName) {
JPanel p = new JPanel();
p.add(new JLabel(nodeName));
p.add(new JTextField(nodeName));
return p;
}}