How to add button to JTextPane
1 posts in topic
Flat View  Flat View

Posted By:   Sanjay_mishra
Posted On:   Monday, December 10, 2001 02:42 AM

Please tell me how to add JButton and other components like JLabel to a JTextPane.

Re: How to add button to JTextPane

Posted By:   Jon_Benton  
Posted On:   Monday, December 10, 2001 08:24 PM

I'll bet you don't reallywant to add a button or a label into a JTextPane. What you probably want to do is add those components so that they are nearthe JTextPane, but not init.


If you really want to, you can add anycomponent to a JTextPane, from ImageIcons to fully interactive components like a JFileChooser, JColorChooser, or your own component. They will appear in-line with the text, and scroll around just like strings.

See JTextPane's insertComponent and insertIcon methods.

Cool, but probably not what you're looking for.

If you just want to have a button or other component placed neatly near your text, then you should investigate use of the various LayoutManagers. I would suggest a quick spin through Sun's excellent Swing tutorial for that.



About | Sitemap | Contact