Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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");


Should I use 2D painting? Or put JLabels in array list and use Point? Need help.
Posted
Updated 27-Aug-14 12:10pm
v2
Comments
TorstenH. 1-Sep-14 2:58am    
what are you trying to do?
.eclipseWarrior 2-Sep-14 13:40pm    
Trying to connect my JLabels with a line, I'm making family tree.

1 solution

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.
 
Share this answer
 
Comments
.eclipseWarrior 3-Sep-14 7:40am    
Thank you. ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900