Sign in to follow this  
ManaStone

[java] How can I set a component size inside of JTextPane.

Recommended Posts

I am trying to add one of my own classes derived from JComponent into a JTextPane Object. Whenever I do this, the size of my component changes to 1 pixel in height and it looks like a straight line. Is there any way I can set the size of a component inside of JTextPane?

Share this post


Link to post
Share on other sites
Why are you trying to add a component directly to a text pane? That would make the component appear on top of some of your text, thereby defeating the purpose of having the text there in the first place. Try it this way instead:


JPanel panel = new JPanel(new BorderLayout());

JComponent customComponent = new CustomComponent(...);
customComponent.setPreferredSize(new Dimension(...));

JTextPane textPane = new JTextPane(...);

panel.add(textPane, BorderLayout.CENTER);
panel.add(customComponent, BorderLayout.XYZ); // replace XYZ with a valid constant



The above technique would place your custom component next to the text pane, leaving both components fully visible.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dathgale
Why are you trying to add a component directly to a text pane?


I am trying to create an Esperanto Tutorial. It is formatted so that there is a header panel at the top where lessons can be selected. There is a submenu panel on the left where the user can select a subsection of the lesson. On the main section there is a JTextPane object in which each lesson part is loaded onto. I want the Text Pane to be static and wide as possible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this