Re: Best Approach for putting words on a JPanel (with special requirements) [2nd attempted post]
- From: Thomas Hawtin <usenet@xxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Dec 2005 17:48:52 +0000
PaulSchrum wrote:
I want to place text on a JPanel (which is a member of a JScrollPane). I want each word to be discrete entity, and I want to have absolute control over the font, size, etc of the text, along with absolute control of the position of the text on the JPanel.
My first attempt was just to .drawString the words on the JPanel and I got that to work fine. But now I need each word to be aware of mouseOvers and mouseClicks, stuff like that. Using .drawString they are not.
I can see two obvious routes you can take.
Carry on in the direction of your first attempt. Probably introduce your own class for representing each word. Have mouse and mouse motion listeners on the main component find the target word instance and call appropriate methods on that.
Alternatively represent each word with a JLabel or custom component. Give the panel a custom LayoutManager that positions each word component as you wish.
BTW, if you are just going to override paintComponent and draw, extending JComponent is more logical the JPanel. In either case you should probably setOpaque(true).
Tom Hawtin -- Unemployed English Java programmer http://jroller.com/page/tackline/ .
- Follow-Ups:
- References:
- Prev by Date: Re: color pallet
- Next by Date: Re: Input Verifier for JComboBox
- Previous by thread: Best Approach for putting words on a JPanel (with special requirements) [2nd attempted post]
- Next by thread: Re: Best Approach for putting words on a JPanel (with special requirements) [2nd attempted post]
- Index(es):