我想讓一個節點成爲一個可點擊的URL,但我似乎無法弄清楚如何。Java JTree節點是一個可點擊的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);
}
}
我爲是有點小白的道歉,但你必須從某個地方開始,對不對?
如果有人能指引我正確的方向,我將非常感激!祝大家晚安!
太棒了!非常感謝你的幫助。我明天早上下班的時候會考慮一下。我今晚沒有時間了。非常感謝,我一定會更新這個主題。 – TheGreyNight
@ TheGreyNight不客氣!讓我知道是否有任何不完整的意義或可以使用更好的解釋。 – avojak