Using JTextPane as JTextField

Hi all!
I need to use a JTextPane as if it was a JTextField: at first I used JTextField and everything worked fine but then I had to color the text the user types and only JTextPane allows me to do that.
BUT I would like to use this JTextPane exactly like I use JTextField and this means that when the user types in the JTextPane I would like to "scroll" the text automatically as it happens in JTextField, with no wrapping.
I searched the forum and I found only temporary hacks...nothing really elegant...
Does anybody knows THE solution to this topic?
Thank you in advance
Gio :-)

Hi!
I apologize...sometimes I'm an idiot!!!
you were right...I solved my problem with this:
            JTextPane t = new JTextPane() {
                    public boolean getScrollableTracksViewportWidth() {
                         return false;
                    public boolean getScrollableTracksViewportHeight() {
                         return false;
            };and then I put the JTextPane into a JScrollPane without scrollbars.
This way I can use a JTextPane as JTextField (well, 95%...) but it works for my purpose!
Gio :-)

Similar Messages

  • How to print JTextPane containing JTextFields, JLabels and JButtons?

    Hi!
    I want to print a JTextPane that contains components like JTextFields, JLabels and JButtons but I do not know how to do this. I use the print-method that is available for JTextComponent since Java 1.6. My problem is that the text of JTextPane is printed but not the components.
    I wrote this small programm to demonstrate my problem:
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.print.PrinterException;
    public class TextPaneTest2 extends JFrame {
         private void insertStringInTextPane(String text,
                   StyledDocument doc) {
              try {
                   doc.insertString(doc.getLength(), text, new SimpleAttributeSet());
              catch (BadLocationException x) {
                   x.printStackTrace();
         private void insertTextFieldInTextPane(String text,
                   JTextPane tp) {
              JTextField tf = new JTextField(text);
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(tf);
         private void insertButtonInTextPane(String text,
                   JTextPane tp) {
              JButton button = new JButton(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(button);
         private void insertLabelInTextPane(String text,
                   JTextPane tp) {
              JLabel label = new JLabel(text) {
                   public Dimension getMaximumSize() {
                        return this.getPreferredSize();
              tp.setCaretPosition(tp.getDocument().getLength());
              tp.insertComponent(label);
         public TextPaneTest2() {
              StyledDocument doc = new DefaultStyledDocument();
              StyledDocument printDoc = new DefaultStyledDocument();
              JTextPane tp = new JTextPane(doc);
              JTextPane printTp = new JTextPane(printDoc);
              this.insertStringInTextPane("Text ", doc);
              this.insertStringInTextPane("Text ", printDoc);
              this.insertTextFieldInTextPane("Field", tp);
              this.insertTextFieldInTextPane("Field", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertButtonInTextPane("Button", tp);
              this.insertButtonInTextPane("Button", printTp);
              this.insertStringInTextPane(" Text ", doc);
              this.insertStringInTextPane(" Text ", printDoc);
              this.insertLabelInTextPane("Label", tp);
              this.insertLabelInTextPane("Label", printTp);
              this.insertStringInTextPane(" Text Text", doc);
              this.insertStringInTextPane(" Text Text", printDoc);
              tp.setEditable(false);
              printTp.setEditable(false);
              this.getContentPane().add(tp);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(400,400);
              this.setVisible(true);
              JOptionPane.showMessageDialog(tp, "Start printing");
              try {
                   tp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
              try {
                   printTp.print();
              } catch (PrinterException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              new TextPaneTest2();
    }First the components are shown correctly in JTextPane, but when printing is started they vanish. So I created another textPane just for printing. But this does not work either. The components are not printed. Does anybody know how to solve this?
    Thanks!

    I do not know how I should try printComponent. From the API-Doc of JComponent of printComponent: This is invoked during a printing operation. This is implemented to invoke paintComponent on the component. Override this if you wish to add special painting behavior when printing. The method print() in JTextComponent is completely different, it starts the print-job. I do not understand how to try printComponent. It won't start a print-job.

  • How can i use RTFEditorKit for JTextField.

    hi all,
    how can i use RTFEditorKit for JTextField.
    thanks in advance
    daya

    Don't cross post. This is a Swing related question and you have already posted in the Swing forum:
    http://forum.java.sun.com/thread.jspa?threadID=619619&tstart=0

  • Using jtextpane as jlist cell renderer component

    hi,
    I want to use Jlist (in a Jscrollpane) to list a series of boxes of text. The boxes have to be kept the same width, but the height can vary depending on the amount of text.
    I want to use jtextpane because it wraps automatically on word boundaries... although I am confused by the jtextpane functionality...
    but I just can't seem to crack it: presumably its going to involve
    class MyCellRenderer extends JTextPane implements CellRenderer {
    public Component getListCellRendererComponent( ...
    then what ??? help!
    mike rodent
    PS also, how to make Jlist put a line (a single line) between each of the components in its list... it's no good doing setBorder inside the above method, as you then get 2 lines coalescing between adjacent Jlist elements...

    PS also, how to make Jlist put a line (a single line) between each of
    the components in its list... it's no good doing setBorder inside the
    above method, as you then get 2 lines coalescing between adjacent
    Jlist elements...Who says you need to have a Border with top and bottom lines?

  • Syntax highlighting using JTextPane

    Hello,
    Does somebody know how to achieve quick, efficient syntax highlighting using JTextPane. I have tried it out by actually removing and reinserting the colored text, but it is way too slow. It is worse if I do it in a thread. It will be a great help if somebody bails me out of this problem.
    S. Senthil kumar

    Let me see if I understand your problem...you are attempting to open a fairly large file and then highlight certain portions of the text. You're asking for help on how to efficiently do this and several people gave you links on how to highlight text which leads to your last question about the files taking too long to load. How big are these files you're talking about and how long does it take for them to load? What time is acceptable? Remember, all commercially available document display programs have a certain load time which grows larger as the document it is attempting to display grows in size.
    -Kevin

  • Problem using JTextPane with large styled docs

    I have an environment where we need to parse out large (5MB) log files, and I'm displaying them with colorized attributes such as logging level, timestamp, etc. The files are read in once and never changed, only displayed - the text is not editable, so we don't care about future updates to the doc (only highlighting text for find/copy). However we do need the entire document 'available' after load in order to do string searches and certain operations linked to the entry a piece of text is in.
    Parsing and building the styled document are relatively fast operations (a couple seconds), but when I set the document on the JTextPanel (which is inside a JScrollBar), it can take an enormous amount of time to display, and sometimes eats up every resource on the machine, eventually stoping dead without displaying at all (out of memory maybe?).
    I've read similar posts on the forum, but no one has provided a clear-cut solution to this problem. Is there a simple way to make my document display quickly? Alternatively, is there another way to implement this without using JTextPane?
    Any help is much appreciated.
    Thanks,
    lex

    In the past I tried to optimize ParagraphView and SectionView of the kit. Don't know whether it will help in your case. Hope so.
    import javax.swing.text.*;
    import java.awt.Rectangle;
    import javax.swing.SizeRequirements;
    import java.awt.Shape;
    public class OptimizedParagraphView extends ParagraphView {
        public OptimizedParagraphView(Element elem) {
            super(elem);
        protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
            //optimized
            int preferred = 0;
            int n = getViewCount();
            for (int i = 0; i < n; i++) {
                View v = getView(i);
                spans[i] = (int) v.getPreferredSpan(axis);
                offsets=preferred;
    preferred += spans[i];
    protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
    //optimized
    int n = getViewCount();
    for (int i = 0; i < n; i++) {
    View v = getView(i);
    int min = (int) v.getMinimumSpan(axis);
    offsets[i] = 0;
    spans[i] = Math.max(min, targetSpan);
    public int getResizeWeight(int axis) {
    //optimized
    return 0;
    public float getAlignment(int axis) {
    //opimized
    return 0;
    protected View createRow() {
    //optimized
    return new OptimizedRow(getElement());
    class OptimizedRow extends BoxView {
    SizeRequirements mimorRequirements;
    OptimizedRow(Element elem) {
    super(elem, View.X_AXIS);
    protected void loadChildren(ViewFactory f) {
    public AttributeSet getAttributes() {
    View p = getParent();
    return (p != null) ? p.getAttributes() : getElement().getAttributes();
    public float getAlignment(int axis) {
    if (axis == View.X_AXIS) {
    switch (StyleConstants.getAlignment(getAttributes())) {
    case StyleConstants.ALIGN_LEFT:
    return 0;
    case StyleConstants.ALIGN_RIGHT:
    return 1;
    case StyleConstants.ALIGN_CENTER:
    case StyleConstants.ALIGN_JUSTIFIED:
    return 0.5f;
    return 0;
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
    Rectangle r = a.getBounds();
    View v = getViewAtPosition(pos, r);
    if ((v != null) && (!v.getElement().isLeaf())) {
    // Don't adjust the height if the view represents a branch.
    return super.modelToView(pos, a, b);
    r = a.getBounds();
    int height = r.height;
    int y = r.y;
    Shape loc = super.modelToView(pos, a, b);
    r = loc.getBounds();
    r.height = height;
    r.y = y;
    return r;
    public int getStartOffset() {
    int offs = Integer.MAX_VALUE;
    int n = getViewCount();
    for (int i = 0; i < n; i++) {
    View v = getView(i);
    offs = Math.min(offs, v.getStartOffset());
    return offs;
    public int getEndOffset() {
    int offs = 0;
    int n = getViewCount();
    for (int i = 0; i < n; i++) {
    View v = getView(i);
    offs = Math.max(offs, v.getEndOffset());
    return offs;
    protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
    baselineLayout(targetSpan, axis, offsets, spans);
    protected SizeRequirements calculateMinorAxisRequirements(int axis,
    SizeRequirements r) {
    mimorRequirements= baselineRequirements(axis, r);
    return mimorRequirements;
    protected SizeRequirements baselineRequirements(int axis, SizeRequirements r) {
    if (r == null) {
    r = new SizeRequirements();
    int n = getViewCount();
    // loop through all children calculating the max of all their ascents and
    // descents at minimum, preferred, and maximum sizes
    int span=0;
    for (int i = 0; i < n; i++) {
    View v = getView(i);
    // find the maximum of the preferred ascents and descents
    span = Math.max((int)v.getPreferredSpan(axis),span);
    r.preferred = span;
    r.maximum=span;
    r.minimum=span;
    return r;
    protected int getViewIndexAtPosition(int pos) {
    // This is expensive, but are views are not necessarily layed
    // out in model order.
    if(pos < getStartOffset() || pos >= getEndOffset())
    return -1;
    for(int counter = getViewCount() - 1; counter >= 0; counter--) {
    View v = getView(counter);
    if(pos >= v.getStartOffset() &&
    pos < v.getEndOffset()) {
    return counter;
    return -1;
    protected short getLeftInset() {
    View parentView;
    int adjustment = 0;
    if ((parentView = getParent()) != null) { //use firstLineIdent for the first row
    if (this == parentView.getView(0)) {
    adjustment = firstLineIndent;
    return (short)(super.getLeftInset() + adjustment);
    protected short getBottomInset() {
    float lineSpacing=StyleConstants.getLineSpacing(getAttributes());
    return (short)(super.getBottomInset() + mimorRequirements.preferred * lineSpacing);
    protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
    //optimized
    int preferred = 0;
    int n = getViewCount();
    for (int i = 0; i < n; i++) {
    View v = getView(i);
    spans[i] = (int) v.getPreferredSpan(axis);
    offsets[i]=preferred;
    preferred += spans[i];
    public int getResizeWeight(int axis) {
    //optimized
    return 0;
    import javax.swing.text.*;
    public class OptimizedSectionView extends BoxView {
    public OptimizedSectionView(Element elem) {
    super(elem,View.Y_AXIS);
    protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
    //optimized
    int preferred = 0;
    int n = getViewCount();
    for (int i = 0; i < n; i++) {
    View v = getView(i);
    spans[i] = (int) v.getPreferredSpan(axis);
    offsets[i]=preferred;
    preferred += spans[i];
    public int getResizeWeight(int axis) {
    //optimized
    return 0;
    public float getAlignment(int axis) {
    //opimized
    return 0;
    class MyViewFactory implements ViewFactory {
    * Creates view for specified element.
    * @param elem Element parent element
    * @return View created view instance.
    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 OptimizedParagraphView(elem);
    // return new ParagraphView(elem);
    else if (kind.equals(AbstractDocument.SectionElementName)) {
    return new OptimizedSectionView(elem);
    // 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);
    // default to text display
    return new LabelView(elem);
    regards,
    Stas

  • Set images on to JTextPane from JTextField or JTextPane using ":)"

    Hi,
    Please see my problem
    jtf = JTextField();
    ae = ActionEvent
    jta = JTextPane();
         if(ae.getSource() == jtf)
                   String Sticon = jtf.getText();
                   //jta.setText(Sticon);
                   System.out.println(Sticon);
                   if(Sticon == ":)" || Sticon.equals(":)"))
                        jta.insertIcon(new ImageIcon("07.gif"));
                        System.out.println("inside sticon");
                   else
                        jta.setText(Sticon);
                   jtf.setText("");
    Help please
    Thanks

    Do not use a test like if (Sticon == ":)")... for a String you always have to use the equals()[b] method.

  • Using jtextpane

    hi,
    im trying to use the JTextPane in such a way that i take input in the the JTextField and on hitting enter i send it to JTextPane. here im using the SETTEXT(STRING S) method to send the text to the JTextPane. the problem is this that all the code works well but the message is not shown on the text pane..................please give urgent response.

    Try the following
    // Do them during initialization
    JTextPane txtOutput = new JTextPane();
    StyledDocument document = txtOutput.getStyledDocument();
    // Define style for output
    Style normalStyle = document.addStyle("Normal", null);
    StyleConstants.setItalic(normalStyle, false);
    StyleConstants.setFontFamily(normalStyle, "Courier");
    StyleConstants.setFontSize(normalStyle, 11);
    StyleConstants.setForeground(normalStyle, Color.black);
    // Now to insert string at end
    document.insertString(document.getLength(), "Hello World!!!", normalStyle );Hope it helps
    Amitabh

  • How to embed image in html when using JTextPane, HTMLEditorKit, JavaMail

    I am developing a specialized e-mail client that has to be able to send e-mail messages (in html format with images and attachments) that can be read by standard e-mail clients, and receive similar messages from standard e-mail clients.
    I have everything working except for embedding images.
    Images are to appear in the document mixed in with the text, but that's not what I mean by "embed". By "embed" I mean that the image itself is encoded within the html.
    Here's a bit of code to set the context.
    JTextPane bodyPane = new JTextPane();
    bodyPane.setEditorKit(htmlEditorKit);
    bodyPane.setTransferHandler(new DropHandler());
    bodyPane.setDocument(new HTMLDocument());
    In the DropHandler I have the following:
    HTMLDocument htmlDoc = (HTMLDocument) bodyPane.getDocument();
    HTMLEditorKit htmlKit = (HTMLEditorKit) bodyPane.getEditorKit();
    int caretPos = bodyPane.getCaretPosition();
    At this point get "filename", the full path to an image file that has been dropped onto bodyPane.
    String htmlString = "<img src=\"file:///" + filename.replace("\\","/") + "\">";
    htmlKit.insertHTML(htmlDoc, caretPos, htmlString, 0, 0, HTML.Tag.IMG);
    This works just fine. The image is displayed in the document at the point of insertion.
    However, the image itself is an external file. I need to send an e-mail with this image and could send the image file as an attachment, but I obviously can't assume that the recipient of the email is going to save the attachment into the proper location.
    What is the best way to do this?
    There is a technique for embedding the actual image in the html, using this syntax:
    String htmlString = "<a href=\"data:image/png;base64,---mimed png image here--\" alt=\"Red dot\"></a>";
    I can't get this to work in JTextPane, so perhaps it's not supported. Also, there may be limitations on the size of an image. And apparently Internet Explorer doesn't support this.
    From what I read, using a "content identifier", that is, "cid:" and adding the image as another part of the e-mail message is probably the thing to do. I haven't taken the time to explore this yet.
    Does JTextPane support cid? Is that a nonsense question? I suspect what I need to do when the message is being composed is use absolute paths to local files with the images, and then when assembling the e-mail, attach the files and rewrite the html to build in the cid linkage. Similarly, when reading a message with cid's, the thing to do is save the body parts as files and rewrite the cid to point to the actual file.
    I have seen others ask similar questions, one as recently as last December, and the reply was to refer to a Sun tutorial. But that tutorial doesn't address the full problem of 1) inserting an image into a document (instead of attaching an image to a component) and 2) sending it as an e-mail message.
    I have yet to see an example that shows the complete package.
    Am I right that the data option I mentioned is not going to work?
    Am I right that cid is the best approach, and do I understand how to use it?
    Is there something else?
    Thanks
    John

    Hi Rocky,
    Are you using the DC?
    if yes then you need to put the image inside the component folder. after that close the application
    & reopen. You will get the image.
    In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
    Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
    Regards
    Chander Kararia

  • Printing RTF-Text using JTextPane

    G'day
    Does someone know how to print the drawed content of a JTextPane/JEditorPane?
    I derived a class from JTextPane and implemented Printable:
    public void print(Graphics g)
      paintComponent(g);
    public void paintComponent(Graphics g)
      super.paintComponent(g);
    }Seems a little ugly, uhm?! It does not work :(
    I get the following errors:
    java.lang.NullPointerException
         at java.util.Hashtable.get(Hashtable.java:336)
         at java.awt.Component.getFontMetrics(Component.java:2503)
         at javax.swing.JComponent.getFontMetrics(JComponent.java:1589)
         at com.sun.java.swing.SwingUtilities2.getFRC(SwingUtilities2.java:368)
         at com.sun.java.swing.SwingUtilities2.drawChars(SwingUtilities2.java:576)
         at javax.swing.text.Utilities.drawTabbedText(Utilities.java:159)
         at javax.swing.text.GlyphPainter1.paint(GlyphPainter1.java:102)
         at javax.swing.text.GlyphView.paintTextUsingColor(GlyphView.java:472)
         at javax.swing.text.GlyphView.paint(GlyphView.java:463)
         at javax.swing.text.BoxView.paintChild(BoxView.java:144)
         at javax.swing.text.BoxView.paint(BoxView.java:407)
         at javax.swing.text.BoxView.paintChild(BoxView.java:144)
         at javax.swing.text.BoxView.paint(BoxView.java:407)
         at javax.swing.text.ParagraphView.paint(ParagraphView.java:584)
         at javax.swing.text.BoxView.paintChild(BoxView.java:144)
         at javax.swing.text.BoxView.paint(BoxView.java:407)
         at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1338)
         at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:643)
         at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:781)
         at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:760)
         at javax.swing.JComponent.paintComponent(JComponent.java:743)
         at fd.gui.Component.paintComponent(Component.java:149)Does that make any sense?
    Btw: I used Sun JRE 1.5 (Ubuntu)
    Cahadras
    Edited by: Cahadras on Oct 23, 2007 1:50 PM

    Cahadras wrote:
    ....It must be an internal bug of the Sun VM that causes this NullPointerException when the JTextPane class passes Font instances to JComponent.getFontMetrics().You may be right, but I'm going to say "careful there partner" to your statement claiming that the Sun VM must have a bug. Please see this excellent web site titled "How to Ask Questions the Smart Way" and is found here:
    http://www.catb.org/~esr/faqs/smart-questions.html
    Here's a subsection of that page titled:
    Don't Claim that you've found a bug:
    When you are having problems with a piece of software, don't claim you have found a bug unless you are very, very sure of your ground. Hint: unless you can provide a source-code patch that fixes the problem, or a regression test against a previous version that demonstrates incorrect behavior, you are probably not sure enough. This applies to webpages and documentation, too; if you have found a documentation �bug�, you should supply replacement text and which pages it should go on.
    Remember, there are many other users that are not experiencing your problem. Otherwise you would have learned about it while reading the documentation and searching the Web (you did do that before complaining, didn't you?). This means that very probably it is you who are doing something wrong, not the software.
    The people who wrote the software work very hard to make it work as well as possible. If you claim you have found a bug, you'll be impugning their competence, which may offend some of them even if you are correct. It's especially undiplomatic to yell �bug� in the Subject line.
    When asking your question, it is best to write as though you assume you are doing something wrong, even if you are privately pretty sure you have found an actual bug. If there really is a bug, you will hear about it in the answer. Play it so the maintainers will want to apologize to you if the bug is real, rather than so that you will owe them an apology if you have messed up.

  • Use MousePressed with JTextField

    Hi all,
    I am now facing a problem with the MouseEvent on JTextField.
    I used loop to create a JTextField array to store something. And now, if I click the TextField, the field will change color and a new value will be stored in that textfield array. But I would like to know how to indicate that mouse press action is related to which textfield? Should I use .getSource() ?
    Thanks!
    CK

    Hallo,
    I think that you have posted this in the wrong forum.

  • Using setBounds on JTextFields within JPanel

    Hi folks,
    I hope someone can help me with this.
    Basically the heirarchy of my UI is as follows:
    The top level JFrame has a borderlayout. The north contains a couple of JButtons and the center contains a JTabbedPane.
    Each tab in the JTabbedPane is borderlayout, with the South having another JTabbedPane, and the Center having a JPanel containing other UI elements.
    In one of these JPanels I want to show a schematic of a plant and on top if over textfields in different locations to current values for different sensors. lets call this JPanel schematicPanel
    For schematicPanel I have set the layout to OverlayLayout. The bottom layer for the schematicPanel is a JLabel that is the actual schematic of the plant. The next layer of the schematicPanel is a JPanel that contains all the JTextFields. This JPanel is set to be transparent using setOpaque(false)
    For the JPanel that contains the JTextFields I have not set a layout. What I want to do is use setBounds, or setLocation to place the JTextFields in the correct locations. Unfortunately those methods have no affect what so ever.
    I have no idea what is wrong.
    Thanks for any help that anyone can offer
    Shabbir
    PS. I tried place the JTextFields directly on the schematicPanel but using setAlignmentX and setAlignmentY does not work very well, and is very cumbersome. If there is a way to make it work I am open to suggestions. Thanks.

    Firstly, in swing the default layout is BorderLayout.
    So when you have not set any layouts the layout is Borderlayout.Now if you want the setBounds(),setLocation() etc methods to take effect for any component the Layout needs to be expicitely set to null.
    ThereFore,set the Layout of the JPanel where you want to place JTextFields to null for eg panel.setLayout(null) and then see how the setBounds(),setLocation() etc methods take effect.
    Got It!!!
    PK

  • Multi-document Application using JTextPane - Issue

    Hi.
    I'm making a java IDE as a class assignment where the user opens a certain project and all associated files open (i.e. all files in the requested folder). Opening is not an issue but here's the real problem. When a file opens (in the JTextPane), the user should be able to edit it. Although my program enables this, what also happens is that if the user switches onto viewing another file (i.e. clicking a file name from a tree in the file pane) the previously open file obviously closes and nothing is saved. I don't want to save the users edits in the actual file until and unless the user themselves click save, but 'd like the application to store the intermediate state of documents until a save request or until the program is terminated. Is there any easy way of doing this?
    Thanks.

    {color:#000080}Cross posting.{color}
    http://forum.java.sun.com/thread.jspa?threadID=5217794&tstart=0
    {color:#000080}Cross posting is rude.
    db{color}

  • Problem about using JTextPane in JScrollPane

    I put a JTextPane in a JScrollPane.
    But when I reduce the window size of the JScrollPane with my mouse, the text line in the JTextPane is broken to newlines automatically due to the reduced window size.
    How to prevent the text lines breaking in this situation!

    OK, so the words are wrapping when they're not suppose to. How are you adding your JTextPane to the JScrollpane? Also, does setting a preferred size or a minimum size on the JTextPane help?
    That's an odd problem. In looking at the API I see that JTextArea and JTextPane are both derived (eventually) from JTextComponent. But the line wrap option is only in JTextArea. This makes me think that it would be possible to overload paint method of the JTextPane. But wow! That would be messy.
    I'll keep thinking about it. Let us know if you find a solution.

  • Using GridBagLayout with JTExtField

    Hello Everybody,
    I use the GridBagLayout to lay out panels, and one of them also uses a GridBag. In this panel there are some textfields. When you type into one of them, that causes the panel's size to change and therefore, it changes sizes of all neighboring panels.
    What can be wrong?
    Here is how I initialize constraints for input fields (and there are also fixed labels before each text field);
    cns.ipady=1;
    cns.ipadx=1;
    cns.weightx=0;
    cns.weighty=0;
    cns.fill = GridBagConstraints.NONE;
    cns.anchor = GridBagConstraints.EAST;
    layout.setConstraints(label, cns);
    and for text fields
    cns.fill = GridBagConstraints.HORIZONTAL;
    cns.gridwidth = GridBagConstraints.REMAINDER;
    cns.weightx=1.0;
    cns.weighty=0;
    layout.setConstraints(tf, cns);
    thanks,
    Sergej.

    Been there myself
    http://forum.java.sun.com/thread.jsp?forum=57&thread=364047

Maybe you are looking for