怎么根据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?
解决方案 »
- java 栈内存,堆内存,方法区,常量池,静态去到底有什么关联, 方法区,常量池,静态区又存在哪里啊,栈中,还是另外的一块空间?
- getResourceAsStream
- java画图问题
- 请问怎么用JAVA对一个文件进行base64编码
- java多线程分片处理大文本文件
- Java如何实现EAS算法
- 一个连接SQL Server的问题,请各位帮帮忙!!!
- 怎么将字符串名转为变量?
- poi操作Excel,将表格内容中1-1-1.xls修改成1_1-1.xls
- 看完了think in 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;
}}