如何在JLabel之间绘制线条? [英] How do I draw lines between my JLabels?

查看:54
本文介绍了如何在JLabel之间绘制线条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在google上搜索了很多关于这个主题的内容,但是却找不到合适的解决方案。

创建JLabels的部分代码:



I searched a lot on google on this subject, but just can't come out with right solution.
Part of my code with JLabels created:

frame = new JFrame();
		frame.setTitle("New family tree");
		...
                JPanel panel = new JPanel();
		panel.setBackground(new Color(30, 144, 255));
		frame.getContentPane().add(panel, BorderLayout.EAST);
		panel.setLayout(new MigLayout("", "[]", "[][][][][][][][]"));

		JButton newPersonButton = new JButton("New Person");
		panel.add(newPersonButton, "cell 0 5");

		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);

		scrollPane = new JScrollPane();
		tabbedPane.addTab("Tree", null, scrollPane, null);

		panel_1 = new JPanel();
		scrollPane.setViewportView(panel_1);
		panel_1.setLayout(new MigLayout("",
				"[][][][][][][][][][][][][][][][][]",
				"[][][][][][][][][][][][][][][][][][][][][]"));

		final JLabel lblAddGreatgrandmother = new JLabel("Add Great-grandmother");
		panel_1.add(lblAddGreatgrandmother, "cell 3 4,growx");

		final JLabel lblAddGrandmother_1 = new JLabel("Add Grandmother");
		panel_1.add(lblAddGrandmother_1, "cell 2 5");





我应该使用2D绘画吗?或者将JLabel放在数组列表中并使用Point?需要帮助。



Should I use 2D painting? Or put JLabels in array list and use Point? Need help.

推荐答案

你应该使用/扩展方法 JPanel.paintComponent() [ ^ ]绘制线条。

即在JComponent中绘制的常用方法。



请看这个链接:



http://www.seas.gwu.edu/~rhyspj/fall05cs143/lec9/lec93.html [ ^ ]



它很好地描述了这个过程。
You should use/extend the method JPanel.paintComponent()[^] to draw lines.
that is a common way to draw in a JComponent.

Please also see this link:

http://www.seas.gwu.edu/~rhyspj/fall05cs143/lec9/lec93.html[^]

It descripes the process pretty well.


这篇关于如何在JLabel之间绘制线条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆