Forums Register Login

Can anybody help??

+Pie Number of slices to send: Send
Dear Friends:

I hope to draw the line between different components in a JPanel, but I hope the line should be a component, ie, it can be clicked, highlighted, selected and deleted instead of just painting a line in a panel,
But I search on web and google a while, I did not find this kind of "Line Component Example" to connect components in JPanel,
Can any guru throw some light or give some example??
Thanks in Advance

Michelle
+Pie Number of slices to send: Send
Try a panel and set its width at 1 pixel??? There isn't a setWidth method but there are several methods allowing you to set sizes.
+Pie Number of slices to send: Send
Hi,

JSplitPane will be the right solution for your problem...
Get help from Java API...

With Regards
Vijay
+Pie Number of slices to send: Send
Take a gander at the very last post in this thread.
+Pie Number of slices to send: Send
Dear friends:
Thanks for reply.
see below Craig's famous and excellent code.
But What I need is that I need all these lines to connect theses components should be independent clickable or selectable components, these lines can be selected, clicked and remove at run time, not painted at design time and like this cannot be selected and deleted,
ie. independent clickable or selectable components are like JButton and JLabels etc, can any grur help??
Thanks.
Michelle.



+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Great!! Thanks so much Craig, How can your guru so smart and so genius?
Highly appreciated.
+Pie Number of slices to send: Send
Dear Sir:
One more question,
[1].how can I adjust the width of the lines I draw in this example??
i.e, make them wider or narrower at my will;
[2]. How to draw arrow lines??
I tried to use Strokes, but fails.

Really sorry to bother.
Thanks
sunny
[ April 24, 2007: Message edited by: girl sunny ]
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Great!! Thanks so much guru, one more question, how to draw line with arrow in this sample??
[ April 24, 2007: Message edited by: girl sunny ]
+Pie Number of slices to send: Send
Changes to SelectableLinks for adding arrow heads to line:
+Pie Number of slices to send: Send
great jobs, great man!! thanks so much, highly appreciated. so wonderful!!
+Pie Number of slices to send: Send
Hi, Craig,
Your sample code is excellent, My case is a little bit different from your one.
[1]. you use Rectangle as a basic component



But my case use JLabel as basic components,

the difference is that in your code:

here only Rectanle has method to call lines[j].intersects(seeker);
but JLabel did not have this method, If I use JLabel, how Can I find a method something like intersects to make sure this line intersects with this JLabel instead of Rectangle?? I check the API already, so far not yet find this kind of method, can you help how to use it??

thanks
+Pie Number of slices to send: Send
you use Rectangle as a basic component
In the getContent method the Rectangle is used to store the [x, y, width, height]
information that is required for setting the location (x,y) and size (width,height) of
each JLabel added to the parent Container with null layout.
In the addLabel method

We are still adding JLabel (as the basic) components but using a null layout which
requires that we specify the location/size for each child component. setBounds is
one way to do this.

the difference is that in your code
...
here only Rectanle has method to call lines[j].intersects(seeker);
but JLabel did not have this method,

In the code block for mousePressed the Rectangle seeker is used as an easy
way to test if the mouse is on top of or close enough to any of the lines which connect
the components. By moving/centering the Rectangle seeker under the mousePressed
location we can test for Rectangle/Line intersection. This will allow the user to select
any of the visible lines that connect the basic components. We are testing for
intersection between the single/movable Rectangle instance seeker and each of the
visible connection lines.

If I use JLabel, how Can I find a method something like intersects to make sure this
line intersects with this JLabel instead of Rectangle??

This is a different question. To test if any line intersects a JLabel (or just about any
other Component) you can use the bounds of the JLabel for the test

Edit: Correct formatting.
[ April 30, 2007: Message edited by: Craig Wood ]
+Pie Number of slices to send: Send
Dear Guru:
Thanks so much for your wonderful code and explanation
[ May 01, 2007: Message edited by: girl sunny ]
+Pie Number of slices to send: Send
Dear Craig:
I tried to apply and integrate your idea and samples into my following code, but not success, can you help some more??
I was really stopped. In the following code, I can dynamically draw line between any components, But I cannot make these lines selectable and deletable. see code below. How to make these lines selectable and deletable by using your methods??

Thanks a lot!



Regards.

Michelle.
+Pie Number of slices to send: Send
To be able to select lines with the mouse you will have to have references to the lines or
construct them for each mousePressed event. This will be difficult to do when you add labels
to the vector and draw connecting lines between components contained in the vector in
paintComponent (the way it is now.)
I would try to add lines to the vector instead of adding labels to the vector. This will
simplify the selection and removal of lines. Adding new lines becomes the problem with this
approach; you'll have to figure out a way to allow the user to add a line between any two
components. After that things should go much smoother.
+Pie Number of slices to send: Send
Dear Craig,
You are right, last night, I tried to add Lines into Vector and hope to dynamically draw lines between JLabels and make these lines selectable, I can draw lines. but failed to select and remove lines, I am still trying and figure it out. your suggestion is very valuable.
Really thanks for your great help.
Regards
Michelle
[ May 02, 2007: Message edited by: girl sunny ]
+Pie Number of slices to send: Send
Once you get the lines in the vector the matter of selecting and removing them is pretty
much the same as used in SelectabeLinks. The only difference is that you are using a vector
instead of an array of lines.
+Pie Number of slices to send: Send
so far not yet success, thanks for advice.
[ May 04, 2007: Message edited by: girl sunny ]
+Pie Number of slices to send: Send
This was more difficult than I had imagined. My last post missed the mark.
This app should allow adding, selecting and removing lines as you wish.
To add a line: press the addLine button and then click any two labels.
The removeLine button will work for selected (red) lines as before.
The app is set up for non-generics, j2se 1.4-
There are generic statements (for the two List/ArrayLists) which you can
uncomment (and comment–out the two non–generic statements right beneath them)
if using j2se 1.5+ and you want to avoid compiler warnings.
+Pie Number of slices to send: Send
Thanks so much for your great help. really appreciated, have a very good weekends. Test success. without you help, I cannot solve this problem.
Best Regards.
Michelle.
The first person to drink cow's milk. That started off as a dare from this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3254 times.
Similar Threads
Multiple components in cell of a JTable
JPanel that needs to show another "window" when I click a component
What does Container mean in Swing
Inheritance help
how do I know what components are in a jpanel?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:11:24.