JEditorPane question

Posted on 2005-04-25
Last Modified: 2010-03-31
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?

Question by:csound
    LVL 15

    Accepted 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);

    Author Comment

    thanx it works now =)
    LVL 15

    Expert Comment

    hahaha :D

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


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This video teaches viewers about errors in exception handling.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now