• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

JEditorPane question

I am using JEditorPane and at the moment when I enter a very long string and if it reaches the width of the JEditorPane, it displays the next part of the string on the next line.

However I want to switch off this function and instead I want the editor to glow in horizontal direction.

Can anyone please tell me how to do this?

  • 2
1 Solution
Use the bellow codes as:
YourTextComponent.setEditorKit(new Wrapper());

This is what you need :

import javax.swing.*;
import javax.swing.text.*;

public class Wrapper extends StyledEditorKit implements ViewFactory {
     private static class NoWrapParagraphView extends ParagraphView {
          public NoWrapParagraphView(Element elem) {
          protected SizeRequirements calculateMinorAxisRequirements(int axis,
                    SizeRequirements r) {
               SizeRequirements req = super
               .calculateMinorAxisRequirements(axis, r);
               req.minimum = req.preferred;
               return req;
          public int getFlowSpan(int index) {
               return Integer.MAX_VALUE;
     public ViewFactory getViewFactory() {
          return this;
     public View create(Element elem) {
          String kind = elem.getName();
          if (kind != null)
               if (kind.equals(AbstractDocument.ContentElementName)) {
                    return new LabelView(elem);
               } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
                    return new NoWrapParagraphView(elem);
               } else if (kind.equals(AbstractDocument.SectionElementName)) {
                    return new BoxView(elem, View.Y_AXIS);
               } else if (kind.equals(StyleConstants.ComponentElementName)) {
                    return new ComponentView(elem);
               } else if (kind.equals(StyleConstants.IconElementName)) {
                    return new IconView(elem);
          return new LabelView(elem);
csoundAuthor Commented:
thanx it works now =)
hahaha :D

Your making a Java IDE I supposed ? Cause I'm making one.
Thanks for your time . . .


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now