【发布时间】:2017-05-30 16:51:17
【问题描述】:
我正在尝试使节点成为可点击的 URL,但我似乎无法弄清楚如何。
我搜索了高低,似乎找不到解决方案。
这是我的代码:
public class NyttigeLinks {
private static JFrame nyttigeLinks;
public static void main(String[] args) {
initialize();
}
public NyttigeLinks() {
}
private static void initialize() {
nyttigeLinks = new JFrame();
nyttigeLinks.setBounds(new Rectangle(0, 0, 350, 650));
nyttigeLinks.getContentPane().setBounds(new Rectangle(0, 0, 350, 650));
nyttigeLinks.getContentPane().setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
nyttigeLinks.getContentPane().setLayout(null);
JLabel logoLabel = new JLabel("");
logoLabel.setIcon(new ImageIcon(NyttigeLinks.class.getResource("/images/ssiLogo.jpg")));
logoLabel.setBounds(0, 0, 350, 60);
JTree tree = new JTree();
nyttigeLinks.getContentPane().add(logoLabel);
JScrollPane scrollPane = new JScrollPane(tree);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBounds(10, 71, 324, 508);
nyttigeLinks.getContentPane().add(scrollPane);
tree.setModel(new DefaultTreeModel(
new DefaultMutableTreeNode("Nyttige Links\t") {
{
DefaultMutableTreeNode node_1;
node_1 = new DefaultMutableTreeNode("Projekt Wiki");
node_1.add(new DefaultMutableTreeNode("AO"));
node_1.add(new DefaultMutableTreeNode("Attends"));
node_1.add(new DefaultMutableTreeNode("Carlsberg"));
node_1.add(new DefaultMutableTreeNode("COOP"));
node_1.add(new DefaultMutableTreeNode("Dafgaard"));
node_1.add(new DefaultMutableTreeNode("Jysk DK"));
node_1.add(new DefaultMutableTreeNode("Jysk SE"));
node_1.add(new DefaultMutableTreeNode("Kvadrat"));
node_1.add(new DefaultMutableTreeNode("Solar"));
node_1.add(new DefaultMutableTreeNode("Stockmann"));
node_1.add(new DefaultMutableTreeNode("Tine"));
node_1.add(new DefaultMutableTreeNode("Unicef"));
node_1.add(new DefaultMutableTreeNode("Vectura"));
add(node_1);
node_1 = new DefaultMutableTreeNode("Helpdesk Norcic");
node_1.add(new DefaultMutableTreeNode("Test"));
add(node_1);
node_1 = new DefaultMutableTreeNode("Test");
node_1.add(new DefaultMutableTreeNode("AO"));
node_1.add(new DefaultMutableTreeNode("Attends"));
node_1.add(new DefaultMutableTreeNode("Carlsberg"));
node_1.add(new DefaultMutableTreeNode("COOP"));
node_1.add(new DefaultMutableTreeNode("Dafgaard"));
node_1.add(new DefaultMutableTreeNode("Jysk DK"));
node_1.add(new DefaultMutableTreeNode("Jysk SE"));
node_1.add(new DefaultMutableTreeNode("Kvadrat"));
node_1.add(new DefaultMutableTreeNode("Solar"));
node_1.add(new DefaultMutableTreeNode("Stockmann"));
node_1.add(new DefaultMutableTreeNode("Tine"));
node_1.add(new DefaultMutableTreeNode("Unicef"));
node_1.add(new DefaultMutableTreeNode("VecturaAO"));
node_1.add(new DefaultMutableTreeNode("Attends"));
node_1.add(new DefaultMutableTreeNode("Carlsberg"));
node_1.add(new DefaultMutableTreeNode("COOP"));
node_1.add(new DefaultMutableTreeNode("Dafgaard"));
node_1.add(new DefaultMutableTreeNode("Jysk DK"));
node_1.add(new DefaultMutableTreeNode("Jysk SE"));
node_1.add(new DefaultMutableTreeNode("Kvadrat"));
node_1.add(new DefaultMutableTreeNode("Solar"));
node_1.add(new DefaultMutableTreeNode("Stockmann"));
node_1.add(new DefaultMutableTreeNode("Tine"));
node_1.add(new DefaultMutableTreeNode("Unicef"));
node_1.add(new DefaultMutableTreeNode("VecturaAO"));
node_1.add(new DefaultMutableTreeNode("Attends"));
node_1.add(new DefaultMutableTreeNode("Carlsberg"));
node_1.add(new DefaultMutableTreeNode("COOP"));
node_1.add(new DefaultMutableTreeNode("Dafgaard"));
node_1.add(new DefaultMutableTreeNode("Jysk DK"));
node_1.add(new DefaultMutableTreeNode("Jysk SE"));
node_1.add(new DefaultMutableTreeNode("Kvadrat"));
node_1.add(new DefaultMutableTreeNode("Solar"));
node_1.add(new DefaultMutableTreeNode("Stockmann"));
node_1.add(new DefaultMutableTreeNode("Tine"));
node_1.add(new DefaultMutableTreeNode("Unicef"));
node_1.add(new DefaultMutableTreeNode("Vectura"));
add(node_1);
}
}
));
tree.setBounds(10, 71, 324, 540);
tree.setRootVisible(false);
JLabel bottomLabelTop = new JLabel(" Nyttige Links Version 1.0");
bottomLabelTop.setBounds(0, 590, 230, 14);
nyttigeLinks.getContentPane().add(bottomLabelTop);
JLabel bottomLabelBot = new JLabel(" Made by xxx");
bottomLabelBot.setBounds(0, 605, 230, 15);
nyttigeLinks.getContentPane().add(bottomLabelBot);
JButton btnNewButton = new JButton("Admin");
btnNewButton.setIcon(new ImageIcon(NyttigeLinks.class.getResource("/images/appIcon.ico")));
btnNewButton.setBounds(240, 590, 80, 20);
nyttigeLinks.getContentPane().add(btnNewButton);
nyttigeLinks.setPreferredSize(new Dimension(350, 650));
nyttigeLinks.setSize(new Dimension(350, 650));
nyttigeLinks.setResizable(false);
nyttigeLinks.setTitle("Nyttige Links");
nyttigeLinks.setIconImage(Toolkit.getDefaultToolkit().getImage(NyttigeLinks.class.getResource("/images/appIcon.ico")));
nyttigeLinks.setBackground(Color.YELLOW);
nyttigeLinks.setBounds(100, 100, 350, 650);
nyttigeLinks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
nyttigeLinks.setVisible(true);
}
}
我很抱歉有点菜鸟,但你总得从某个地方开始吧?
如果有人能指出我正确的方向,我将不胜感激!祝大家晚安!
【问题讨论】: