user3275944
user3275944

Reputation: 57

Position image in a JTextPane (like using setBounds to position JPanel in a JFrame)

I'm new to Java and I would like to know how to position an image within a JTextPane. Is it possible? Is there any other methods for positioning an image in a JLabel?

Upvotes: 1

Views: 217

Answers (2)

StanislavL
StanislavL

Reputation: 57381

You can create a JLabel for the image, call setBounds() for the image and call jTextPaneInstance.add(theImageLabel).Or you can specify any desired LayoutManager for the jTextPaneInstance and just add the label with appropriate constraint.

If you mean something like text flow around the image it's much much more difficult to implement but also possible (depends on EditorKit you use there).

Upvotes: 1

javawocky
javawocky

Reputation: 919

The gridBagLayout can be used to position components within a JFrame.

Take a look here: http://docs.oracle.com/javase/7/docs/api/java/awt/GridBagLayout.html

I usually use gridLayout,it is less flexible, but easy to use for simple layouts.

Upvotes: 1

Related Questions