JTextPane inside JScrollPane

Hi,
I've seen a lot of possibilities to get a JTextPane into JScrollPane without wraping the text in the forum. None worked for me..
My situation:
JTextPane(editable=false) with given text(DefaultStyledDocument) is inside JScrollPane.
I replace (by pressing a button) some text parts with longer text AND JTextPane wraps it!..
I tried to set the size of the textPane to the computed line width of the longst line, but nothing happened.. (I expected the JScrollPane to show off horizontal scrollbar, because the width of JTextPane is getting bigger than the width of JScrollPane).
Anyone knows how to put formatted text into text- or scrollpane without wraping it?
And who allowed JTextPane to wrap my lines anyway?!
(it's called StyledDocument and not ChaosDocument :)
Thanks in advance!
Raman.

Not sure that JTextPane is the best place to start. The wrapping is controlled by ParagraphView and its underlying structure. Try looking at implementing extensions to the standard EditorKit/ViewFactory to tweak this behaviour

Similar Messages

  • JTextPane inside JScrollPane resizing when updated

    Hiya all,
    I've been struggling with this problem and checking the forums, but didn't find a solution, so I hope someone can help...at least help me for the nice picture :) It has to do with JTextPane's automatically resizing to their content on a GUI update, rather than scrollbars appearing (the desired result).
    Basically, I have a scenario where I am creating a series of multiple choice answers for a question. Each answer consists of a JTextPane inside a JScrollPane, and a JRadioButton, which are all contained in a JPanel (called singleAnswerPanel). So for 2 answers, I would have 2 of these singleAnswerPanels. There is a one large JPanel that contains all the singleAnswerPanels (called allAnswersPanel). This allAnswersPanel is contained in a JScrollPane. Graphically, this looks like:
       |       JPanel (allAnswersPanel) inside a JScrollPane            |
       |                                                                |
       |  ------------------------------------------------------------  |
       | |     JPanel (singleAnswerPanel)                             | |
       | |    ----------------------------------                      | |
       | |   |  JTextPane inside a JScrollPane  |     * JRadioButton  | |
       | |    ----------------------------------                      | |
       | |                                                            | |
       |  ------------------------------------------------------------  |
       |                                                                |
       |                                                                |
       |  ------------------------------------------------------------  |
       | |     JPanel (singleAnswerPanel)                             | |
       | |    ----------------------------------                      | |
       | |   |  JTextPane inside a JScrollPane  |     * JRadioButton  | |
       | |    ----------------------------------                      | |
       | |                                                            | |
       |  ------------------------------------------------------------  |
       |                                                                |
        ----------------------------------------------------------------So above, I show 2 answers that can be filled in with text. So assuming both answer JTextPanes are filled with text beyond their current border (scrollbars appear as expected) and the user wishes to add more answers. I have a button to add another singleAnswerPanel to the containing JPanel (allAnswersPanel), and then I validate the main JScrollPane that contains the allAnswersPanel as it's view. The problem that occurs is the existing single answer JTextPanes resize to the size of their text and the vertical scrollbars (only vertical ones setup) of the JTextPanes dissappear! My intent is to keep the existing JScrollPanes the same size (with their scrollbars) when a new answer is added.
    The code snippet below shows what gets done when a new answer is added:
    private void createAnswer()
        // The panel that will hold the new single answer JTextPane pane
        // (inside a JScrollPane) and radio button.
        JPanel singleAnswerPanel = new JPanel();
        // Create the text pane for the single answer.
        JTextPane singleAnswerTextPane = new JTextPane();
        Dimension dimensions = new Dimension(200, 30);
        singleAnswerTextPane.setPreferredSize(dimensions);
        singleAnswerTextPane.setMaximumSize(dimensions);
        // Create a scroll pane and add the single answer text pane.
        JScrollPane singleAnswerScrollPane =
         new JScrollPane(singleAnswerTextPane);
        // Create a radio button that is associated with the single
        // answer text pane above.
        JRadioButton singleAnswerRadioButton = new JRadioButton();
        // Add the scroll pane and radio button to the panel (for a single
        // answer).
        singleAnswerPanel.add(singleAnswerScrollPane);
        singleAnswerPanel.add(singleAnswerRadioButton);
        // Add the panel holding a single answer to the panel holding
        // all the answers.
        m_allAnswersPanel.add(singleAnswerPanel);
        // Update the display.  m_allAnswersScrollPane is a JScrollPane
        // that has the m_allAnswersPanel (JPanel) as its view.
        m_allAnswersScrollPane.validate();
    }     Sorry for the length of the message, but I really want to solve this problem. So again, when updating the JScrollPane with validate(), the JTextPane for a single answer resizes to it's contents (plain text currently) and loses it's vertical scrollbars, but I want it to stay the same size and maintain the scrollbars.
    Thanks!

    http://java.sun.com/docs/books/tutorial/uiswing/mini/layout.htmlimport javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    public class Test extends JFrame {
        int cnt=0;
        Random r = new Random();
        String[] nouns = {"air","water","men","idjits"};
        JPanel mainPanel = new JPanel(new GridBagLayout());
        JScrollPane mainScroll = new JScrollPane(mainPanel);
        JScrollBar mainScrollBar = mainScroll.getVerticalScrollBar();
        public Test() {
         setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         Container content = getContentPane();
         content.add(new JLabel("QuizMaster 2003"), BorderLayout.NORTH);
         content.add(mainScroll, BorderLayout.CENTER);
         JButton jb = new JButton("New");
         content.add(jb, BorderLayout.SOUTH);
         jb.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent ae) {
              JPanel questionPanel = new JPanel(new GridBagLayout());
              questionPanel.add(new JLabel("Question "+cnt++),
                   new GridBagConstraints(0,0,1,1,0.0,0.0,
                        GridBagConstraints.EAST, GridBagConstraints.NONE,
                        new Insets(1,2,1,2),0,0));
              questionPanel.add(new JLabel("Why is there "+
                            nouns[r.nextInt(nouns.length)]+"?"),
                   new GridBagConstraints(1,0,1,1,0.0,0.0,
                        GridBagConstraints.EAST, GridBagConstraints.NONE,
                        new Insets(1,2,1,2),0,0));
              JTextArea jta = new JTextArea();
              JScrollPane jsp = new JScrollPane(jta);
              jsp.setPreferredSize(new Dimension(300,50));
              questionPanel.add(jsp, new GridBagConstraints(0,1,2,1,0.0,0.0,
                        GridBagConstraints.EAST, GridBagConstraints.BOTH,
                        new Insets(1,2,1,2),0,0));
              mainPanel.add(questionPanel, new GridBagConstraints(0,cnt,1,1,0.0,0.0,
                            GridBagConstraints.EAST,GridBagConstraints.NONE,
                            new Insets(0,0,0,0),0,0));
              mainPanel.revalidate();
              mainScroll.getViewport().setViewPosition(new Point(0, mainPanel.getHeight()));
         setSize(400,300);
         show();
        public static void main( String args[] ) { new Test(); }
    }

  • Trouble Scrolling down(JTextPane inside JScrollPane)

    I am writting a java interface to the Jabber IM system. I'm trying to allow html in the messages, so I have a JTextPane that I use to show what has been said. In order to scroll, I've placed the JTextPane within a JScrollPane. When a new message needs to be placed into the JTextPane, I set the JTextPane to the proper text and set the scroll bar from the scroll pane to it's .getMaximum() value. My problem is that the .getMaximum() function only gets the NEW, ACTUAL maximum AFTER the JTextPane has been parsed and painted into the JPanel. The time it takes to do this is proportional to the length of the text within the JText pane and relative to the speed of the computer. So, the scroll bars should be done in response to the completion of the painting of the JTextPane instead of a set time delay. I don't know how to do this. I assume I need to overwrite some paint or repaint function, but I don't know which one to overwrite. The JTextPane is in a JScrollPane in a JSplitPane in a JPanel in a JFrame, if that helps at all.
    I've been stuck on this forever..
    Thanks for any help.

    Gave you 6 $. JTextPane doesn't have the insert function, so I've been using setText(). The problem is that the second the Pane is redrawn, it shows the top of the document, then scrolls to the bottom. This takes a fraction of a second, but still is undesireable.
    What I'm trying to do is make a new textpane object, set the text, set the caret position, THEN replace the old pane. The problem is, I can't just use oldPane = newPane because that just makes oldPane reference the new Object.(The object shown is then only referenced from the parent swing component, a JScrollPane) I've tried using the .setViewportView on the JScrollPane that the JTextPane is within, but then it doesn't scroll to the caret position.
    I've gotten it to work once. I had created all new objects(JTextPane within JScrollPane within JSplitPane within JPanel) adding each to it's parent and adding the JPanel to the container. This worked ONCE! I changed the code, then changed it back and it didn't work again...
    Here's the code I have for buffering the JTextPane.
    if(chatPane == chatPaneBuffer2){
    chatPaneBuffer1.setText(chatStringBuffer.toString());
    chatPaneBuffer1.setCaretPosition(chatPaneBuffer1.getDocument().getLength());
    chatPane = chatPaneBuffer1;
    }else{
    chatPaneBuffer2.setText(chatStringBuffer.toString());
    chatPaneBuffer2.setCaretPosition(chatPaneBuffer2.getDocument().getLength());
    chatPane = chatPaneBuffer2;
    This works, but somehow I need the object chatPane is pointing at to be referenced by my JScrollPane.

  • JTextPane inside a JScrollPane: any way to display a certain section?

    I have a GUI with a JTextPane inside a JScrollPane.
    The text of the JTextPane is the contents of a text file, so it typically has many lines.
    I want the JScrollPane (whose preferred size has already been previously set to display 11 rows of text) to always show one target line as the middle row, and the 5 rows before and after it as the remaining 10 rows.
    In other words, I want to show a certain line and its surrounding context.
    Do you guys know how to achieve this? I have already tried calling
    JTextPane.setCaretPositionbut this is inadequate because it merely guarantees that the line with the caret is visible--but it does not guarantee to center the caret line in the middle of the JScrollPane.
    I also tried calling
    textPane.scrollRectToVisible( textPane.modelToView(caretPos) );where textPane is my JTextPane, but this failed completely (seems to always display the final lines of the file).
    Anyone have any suggestions?

    Daryl: thanks for your response.
    My original code looked like this:
    int caretPos = 0;
    for (int i = 0; i <= index; i++) {
         caretPos += lines.length();
    textPane.setCaretPosition(caretPos);
    With *just* the above, you get the behavior that I originally described, namely, the line in question (which is lines[index]) always gets displayed, but it is not necessarily in the middle of the JScrollPane.
    I tried commenting out the line above which calls setCaretPosition, and used essentially your code instead:Rectangle caretRectangle = textPane.modelToView(caretPos);
    Rectangle viewRectangle = new Rectangle(
         0, caretRectangle.y - (scrollPane.getHeight() - caretRectangle.height) / 2,
         scrollPane.getWidth(), scrollPane.getHeight()
    textPane.scrollRectToVisible(viewRectangle);This fails too: the JScrollPane now always shows the bottom of the JTextPane.
    What does work is to use *both* techniques, namely, call setCaretPosition as well as scrollRectToVisible:     // set the caret to the line in question (i.e. at index); this merely guarantees that this line is visible, but not necessarily centered
    int caretPos = 0;
    for (int i = 0; i <= index; i++) {
         caretPos += lines[i].length();
    textPane.setCaretPosition(caretPos);
         // and IN ADDITION cause scrollPane's viewport to be centered around the line
    Rectangle caretRectangle = textPane.modelToView(caretPos);
    Rectangle viewRectangle = new Rectangle(
         0, caretRectangle.y - (scrollPane.getHeight() - caretRectangle.height) / 2,
         scrollPane.getWidth(), scrollPane.getHeight()
    textPane.scrollRectToVisible(viewRectangle);The interesting question is why do you need to do both steps?
    I think that I know the reason, but I would love to see someone confirm or deny this.  What follows is my speculation.
    The above code is inside a method that is call by a run method of the class in question which is always executed by the event dispatch thread (EDT), so it is not an illegal thread use case.  However, in the method that has the code above, I am clearing all existing text of the JTextPane and then repopulating it (with that String[] lines used above, which came from parsing a file).
    Now, in  [this posting|http://forums.sun.com/thread.jspa?messageID=10289999#10289999], camickr claimed:
    "When text is inserted into a Document, behind the scenes a call to setCaretPosition() is made to position the caret after the newly inserted text. However inserting text into a document is a complex procedure since Elements need to be created as the text inserted into the Document is parsed. So the call to the setCaretPosition() method is placed in a SwingUtilities.invokeLater(), which means tha code gets added to the end of the GUI EDT to be executed once the Document is in a complete state. So basically what is happening is that your call to set the view position does execute, but then is gets overridden by the setCaretPosition() method call."
    If the above claim is true, then all the calls in that method to add the file's text result in implicit calls to setCaretPosition which will be executed AFTER the method above ends (i.e. asynchronously, later on by the event dispatch thread).  Hence, I need to do an explicit setCaretPosition call of my own to override these implicit calls.
    Now, I am not sure that I totally buy this explanation.  I would like to see more proof of camickr's claims for one: I did a quick code review of some of the classes involved, and do not see where calling AbstractDocument.insertString generates an implicit call to setCaretPosition on the EDT.  To be sure, the code is complex, and I do not know where exactly to look, and maybe this is done by some listener or something, who knows.  Furthermore, my explicit call to setCaretPosition is done synchronously on the EDT (recall: that method above in my class is called by its run which is executed by the EDT).  So, my explicit call to setCaretPosition should occur in time before all of those delayed implicit calls, and thus should actually be overridden by them, no?
    I would love to hear from someone who really knows Swing...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem in refreshing JTree inside Jscrollpane on Button click

    hi sir,
    i have problem in refreshing JTree on Button click inside JscrollPane
    Actually I am removing scrollPane from panel and then again creating tree inside scrollpane and adding it to Jpanel but the tree is not shown inside scrollpane. here is the dummy code.
    please help me.
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.tree.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.WindowListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class Test
    public static void main(String[] args)
         JFrame jf=new TestTreeRefresh();
         jf.addWindowListener( new
         WindowAdapter()
         public void windowClosing(WindowEvent e )
         System.exit(0);
         jf.setVisible(true);
    class TestTreeRefresh extends JFrame
         DefaultMutableTreeNode top;
    JTree tree;
         JScrollPane treeView;
         JPanel jp=new JPanel();
         JButton jb= new JButton("Refresh");
    TestTreeRefresh()
    setTitle("TestTree");
    setSize(500,500);
    getContentPane().setLayout(null);
    jp.setBounds(new Rectangle(1,1,490,490));
    jp.setLayout(null);
    top =new DefaultMutableTreeNode("The Java Series");
    createNodes(top);
    tree = new JTree(top);
    treeView = new JScrollPane(tree);
    treeView.setBounds(new Rectangle(50,50,200,200));
    jb.setBounds(new Rectangle(50,300,100,50));
    jb.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
              jp.remove(treeView);
              top =new DefaultMutableTreeNode("The Java ");
    createNodes(top);
              tree = new JTree(top);
                   treeView = new JScrollPane(tree);
                   treeView.setBounds(new Rectangle(50,50,200,200));
                   jp.add(treeView);     
                   jp.repaint();     
    jp.add(jb);     
    jp.add(treeView);
    getContentPane().add(jp);
    private void createNodes(DefaultMutableTreeNode top) {
    DefaultMutableTreeNode category = null;
    DefaultMutableTreeNode book = null;
    category = new DefaultMutableTreeNode("Books for Java Programmers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Tutorial: A Short Course on the Basics");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Tutorial Continued: The Rest of the JDK");
    category.add(book);
    book = new DefaultMutableTreeNode("The JFC Swing Tutorial: A Guide to Constructing GUIs");
    category.add(book);
    book = new DefaultMutableTreeNode("Effective Java Programming Language Guide");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Programming Language");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Developers Almanac");
    category.add(book);
    category = new DefaultMutableTreeNode("Books for Java Implementers");
    top.add(category);
    book = new DefaultMutableTreeNode("The Java Virtual Machine Specification");
    category.add(book);
    book = new DefaultMutableTreeNode("The Java Language Specification");
    category.add(book);
    }

    hi sir ,
    thaks for u'r suggession.Its working fine but the
    properties of the previous tree were not working
    after setModel() property .like action at leaf node
    is not working,I'm sorry but I don't understand. I think you are saying that the problem is solved but I can read it to mean that you still have a problem.
    If you still have a problem then please post some code (using the [code] tags of course).

  • Install Application - TextArea inside JScrollPane

    I've been working on an install application to install another one of my programs (next/accept/next/ finish type of thing) and had a couple questions and would appreciate any help anyone can give.
    Some Background info:
    I made images and have them display as image icons through jlabels for the buttons and background. The labels have classes applying various mouselisteners (Mousepressed, MouseEntered, MouseExited, etc) changing the images and moving from screen to screen. I have my layout set to null, not for any particular reason, but because I have no formal education in layout managers.
    1) Is there a conical solution to moving through various windows? That is, right now I move through the various 'screens' with a check on an int called state, that gets incremented and decremented through forward and back buttons. I looked at some code given to us on a test by our teacher (we had to find bugs) and saw that he had implemented a fake "state" interface, with constants like "Account_State" to control where you were in the program. This seems a bit easier to read than ints, but is there a correct built in version of his states?
    2) On the second screen I have a license agreement (actually required for the application that gets installed), and a checkbox. The license is held inside of a JTextArea(scroll) inside a JScrollPane(textscroll). The JScrollPane is extending in weird ways. The following is a stripped down version of my code (it runs and demonstrates the problem):
    InstalleApp
    import javax.swing.*;
    import java.awt.*;
    public class InstalleApp {
        public static void main(String args[]) {
            InstalleFrame m = new InstalleFrame();
               Container content = m.getContentPane();
            m.setDefaultCloseOperation(3);
            m.setSize(550, 400);
            m.setUndecorated(true);
            m.setVisible(true);
            m.setTitle("Install");
    }InstalleFrame
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.JFrame;
    import java.awt.event.*;
    import java.awt.Rectangle;
    import java.awt.Font;
    import java.awt.BorderLayout;
    import java.util.*;
    import javax.swing.event.DocumentEvent;
    import javax.swing.event.DocumentListener;
    import java.awt.event.ActionEvent;
    import javax.swing.text.BadLocationException;
    import javax.swing.JSlider;
    import java.awt.Dimension;
    public class InstalleFrame
        extends JFrame implements ActionListener {
      public InstalleFrame() {
        try {
          jbInit();
        catch (Exception ex) {
          ex.printStackTrace();
      public void actionPerformed(ActionEvent e) {
      JScrollPane textscroll;
      private void jbInit() throws Exception {
        this.getContentPane().setLayout(null);
        this.getContentPane().setBackground(UIManager.getColor("window"));
        background.setBounds(new Rectangle(0, 0, 550, 400));
        readcheck.setOpaque(false);
        readcheck.setText("I have read and accept the license agreement");
        readcheck.setBounds(new Rectangle(31, 357, 319, 32));
        scroll.setWrapStyleWord(true);
        scroll.setLineWrap(true);
        scroll.setText(
            "Copyright ? 2006-2007 GonZor228.com \n\nBy using or distributing this " +
            "software (or any work based on the software) you shall be deemed " +
            "to have accepted the terms and conditions set out below.\n\nGonZor228.com " +
            "(\"GonZor\") is making this software freely available on the basis " +
            "that it is accepted as found and that the user checks its fitness " +
            "for purpose prior to use.\n\nThis software is provided \'as-is\', without " +
            "any express or implied warranties whatsoever. In no event will the " +
            "authors, partners or contributors be held liable for any damages, " +
            "claims or other liabilities direct or indirect, arising from the " +
            "use of this software.\n\nGonZor will from time to time make software " +
            "updates available.  However, GonZor accepts no obligation to provide " +
            "any support to free license holders.\n\nGonZor grants you a limited " +
            "non-exclusive license to use this software for any purpose that does " +
            "not violate any laws that apply to your person in your current jurisdiction, " +
            "subject to the following restrictions: \n\n1. The origin of this software " +
            "must not be misrepresented; you must not claim that you wrote the " +
            "original software.\n2. You must not alter the software, user license " +
            "or installer in any way unless given permission to do so.\n3. This " +
            "notice may not be removed or altered from any distribution.\n4. You " +
            "may not resell or charge for the software.\n5. You may not reverse " +
            "engineer, decompile, disassemble, derive the source code of or modify " +
            "[or create derivative work from] the program without the express " +
            "permission of GonZor.\n6. You must not use this software to engage " +
            "in or allow others to engage in any illegal activity.\n7. You may " +
            "not claim any sponsorship by, endorsement by, or affiliation with " +
            "GonZor228.com\n8. You acknowledge that GonZor owns the copyright and " +
            "all associated intellectual property rights relating to the software.\n\n" +
            " This software license is governed by and construed in accordance " +
            "with the laws of Australia and you agree to submit to the exclusive " +
            "jurisdiction of the Australian courts.\n\nBy clicking the \"I agree\" " +
            "button below, you agree to these software license terms. If you disagree " +
            "with any of the terms below, GonZor does not grant you a license " +
            "to use the software ? exit the window.\n\nYou agree that by your installation " +
            "of the GonZor?s software, you acknowledge that you are at least 18 " +
            "years old, have read this software license, understand it, and agree " +
            "to be bound by its terms.\n\nGonZor reserves the right to update and " +
            "change, from time to time, this software license and all documents " +
            "incorporated by reference. You can always find the most recent version " +
            "of this software license at GonZor228.com.  GonZor may change this " +
            "software license by posting a new version without notice to you. " +
            "Use of the GonZor?s software after such change constitutes acceptance " +
            "of such changes.\n\n1.\tOwnership and Relationship of Parties.\n\nThe " +
            "software is protected by copyrights, trademarks, service marks, international " +
            "treaties, and/or other proprietary rights and laws of the U.S. and " +
            "other countries. You agree to abide by all applicable proprietary " +
            "rights laws and other laws, as well as any additional copyright notices " +
            "or restrictions contained in this software license. GonZor owns all " +
            "rights, titles, and interests in and to the applicable contributions " +
            "to the software. This software license grants you no right, title, " +
            "or interest in any intellectual property owned or licensed by GonZor, " +
            "including (but not limited to) the software, and creates no relationship " +
            "between yourself and GonZor other than that of GonZor to licensee.\n\n" +
            "The software and its components contain software licensed from " +
            "GonZor. The licensor software enables the software to perform certain " +
            "functions including, without limitation, access proprietary data " +
            "on third-party data servers as well as GonZor?s own server. You agree " +
            "that you will use the software, and any data accessed through the " +
            "software, for your own personal non-commercial use only. You agree " +
            "not to assign, copy, transfer, or transmit the software, or any data " +
            "obtained through the software, to any third party. Your license to " +
            "use the software, its components, and any third-party data, will " +
            "terminate if you violate these restrictions. If your license terminates, " +
            "you agree to cease any and all use of the software, its components, " +
            "and any third-party data. All rights in any third-party data, any " +
            "third-party software, and any third-party data servers, including " +
            "all ownership rights are reserved and remain with the respective " +
            "third parties. You agree that these third parties may enforce their " +
            "rights under this Agreement against you directly in their own name.\n\n" +
            "2.\tSupport and Software Updates.\n\nGonZor may elect to provide " +
            "you with customer support and/or software upgrades, enhancements, " +
            "or modifications for the software (collectively, \"Support\"), in its " +
            "sole discretion, and may terminate such Support at any time without " +
            "notice to you. GonZor may change, suspend, or discontinue any aspect " +
            "of the software at any time, including the availability of any software " +
            "feature, database, or content. GonZor may also impose limits on certain " +
            "features and services or restrict your access to parts or all of " +
            "the software or the GonZor228.com web site without notice or liability.\n\n" +
            "3.  \tFees and Payments.\n\nGonZor reserves the right to charge fees " +
            "for future use of or access to the software in GonZor?s sole discretion. " +
            "If GonZor decides to charge for the software, such charges will be " +
            "disclosed to you 28 days before they are applied if such fees will " +
            "affect your use of the product.\n\n4.\tDisclaimer of Warranties by " +
            "GonZor.\n\nUse of the software and any data accessed through the software " +
            "is at your sole risk. They are provided \"as is.\"  Any material or " +
            "service downloaded or otherwise obtained through the use of the software " +
            "(such as the \"plug-in\" feature) is done at your own discretion and " +
            "risk, and you will be solely responsible for any damage to your computer " +
            "system or loss of data that results from the download and/or use " +
            "of any such material or service.  GonZor, its officers, directors, " +
            "employees, contractors, agents, affiliates, assigns, and GonZor?s " +
            "licensors (collectively ?Associates?) do not represent that the software " +
            "or any data accessed there from is appropriate or available for use " +
            "outside the Australia.\n\nThe Associates expressly disclaim all warranties " +
            "of any kind, whether express or implied, relating to the software " +
            "and any data accessed there from, or the accuracy, timeliness, completeness, " +
            "or adequacy of the software and any data accessed there from, including " +
            "the implied warranties of title, merchantability, satisfactory quality, " +
            "fitness for a particular purpose, and non-infringement.\n\nIf the " +
            "software or any data accessed there from proves defective, you (and " +
            "not the Associates) assume the entire cost of all repairs or injury " +
            "of any kind, even if the Associates have been advised of the possibility " +
            "of such a defect or damages. Some jurisdictions do not allow restrictions " +
            "on implied warranties so some of these limitations may not apply " +
            "to you.\n\n5. \tLimitation of liability.\n\nThe Associates will not " +
            "be liable to you for claims and liabilities of any kind arising out " +
            "of or in any way related to the use of the software by yourself or " +
            "by third parties, to the use or non-use of any brokerage firm or " +
            "dealer, or to the sale or purchase of any security, whether such " +
            "claims and liabilities are based on any legal or equitable theory." +
            "\n\nThe Associates are not liable to you for any and all direct, incidental, " +
            "special, indirect, or consequential damages arising out of or related " +
            "to any third-party software, any data accessed through the software, " +
            "your use or inability to use or access the software, or any data " +
            "provided through the software, whether such damage claims are brought " +
            "under any theory of law or equity. Damages excluded by this clause " +
            "include, without limitation, those for loss of business profits, " +
            "injury to person or property, business interruption, loss of business " +
            "or personal information. Some jurisdictions do not allow limitation " +
            "of incidental or consequential damages so this restriction may not " +
            "apply to you.\n\nInformation provided through the software may be " +
            "delayed, inaccurate, or contain errors or omissions, and the Associates " +
            "will have no liability with respect thereto. GonZor may change or " +
            "discontinue any aspect or feature of the software or the use of all " +
            "or any features or technology in the software at any time without " +
            "prior notice to you, including, but not limited to, content, hours " +
            "of availability.\n\n6.  \tControlling Law.\n\nThis software license " +
            "and the relationship between you and GonZor is governed by the laws " +
            "of Australia without regard to its conflict of law provisions. You " +
            "and GonZor agree to submit to the personal and exclusive jurisdiction " +
            "of the courts located within Australia. The United Nations Convention " +
            "on the International Sale of Goods does not apply to this software " +
            "license.\n\n7.\tPrecedence.\n\nThis software license constitutes the " +
            "entire understanding between the parties respecting use of the software, " +
            "superseding all prior agreements between you and GonZor.\n\n8.\tSurviving " +
            "Provisions.\n\nSections 1, and 3 through 5, will survive any termination " +
            "of this Agreement.\n\n---------------------------------------------------------------------------------" +
            "---\nIf you accept the terms of the agreements, click I Agree to continue. " +
            " You must accept the agreement to download and use the software. ");
        scroll.setBounds(new Rectangle(36, 36, 478, 305));
        this.getContentPane().add(readcheck);
        readcheck.setVisible(false);
       this.getContentPane().add(scroll);
       textscroll = new JScrollPane (scroll, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        textscroll.setBounds(36,36,400,400);
          getContentPane().add( textscroll );
        this.getContentPane().add(background);
      JLabel background = new JLabel();
      JCheckBox readcheck = new JCheckBox();
      JTextArea scroll = new JTextArea();
    }Sorry about all the text for the agreement. I've tried a number of different things I got from searching the forums at different points in the code (setting the number of rows/columns, setting max and min sizes, etc etc) The code above that wraps the text I could have sworn I tried 3 times before it magically worked... I also tried using the awt component for textareas that had the scrollbars built in, but scrapped it after having even more difficulties with that one. I'm trying to get the textbox to only go down about 300 px and 300 px to the right. Using the graphical editor to change it produces a null pointer error at compile time(?!?). Can anyone help me to get the textbox to render as I want it to?
    Edited by: rpk5000 on Jan 27, 2008 9:43 AM

    for instance, boxlayout would work nicely with the installer frame (or dialog)
    import java.awt.Dimension;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    public class InstalleFrame
        public InstalleFrame()
            try
                jbInit();
            catch (Exception ex)
                ex.printStackTrace();
        private JScrollPane textscroll;
        private JPanel contentPane = new JPanel();
        private JLabel background = new JLabel();
        private JCheckBox readcheck = new JCheckBox();
        private JTextArea scroll = new JTextArea();
        private void jbInit() throws Exception
            contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
            contentPane.setBackground(UIManager.getColor("window"));
            contentPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
            scroll.setWrapStyleWord(true);
            scroll.setLineWrap(true);
            String text = "Copyright ? 2006-2007 GonZor228.com \n\nBy using or distributing this "
                            + "software (or any work based on the software) you shall be deemed "
                            + "to have accepted the terms and conditions set out below.\n\nGonZor228.com "
                            + "(\"GonZor\") is making this software freely available on the basis "
                            + "that it is accepted as found and that the user checks its fitness "
                            + "for purpose prior to use.\n\nThis software is provided \'as-is\', without "
                            + "any express or implied warranties whatsoever. In no event will the "
                            + "authors, partners or contributors be held liable for any damages, "
                            + "claims or other liabilities direct or indirect, arising from the "
                            + "use of this software.\n\nGonZor will from time to time make software "
                            + "updates available.  However, GonZor accepts no obligation to provide "
                            + "any support to free license holders.\n\nGonZor grants you a limited "
                            + "non-exclusive license to use this software for any purpose that does "
                            + "not violate any laws that apply to your person in your current jurisdiction, "
                            + "subject to the following restrictions: \n\n\nblah, blah, blah,..."
                            + "\n\n";
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 5; i++)
                sb.append(text);
            scroll.setText(sb.toString());
            contentPane.add(readcheck);
            contentPane.add(scroll);
            textscroll = new JScrollPane(scroll,
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            textscroll.setPreferredSize(new Dimension(400, 400));
            contentPane.add(textscroll);
            JPanel bottomPane = new JPanel();
            bottomPane.setOpaque(false);
            final JButton okButton = new JButton("OK");
            final JButton cancelButton = new JButton("Cancel");
            okButton.setEnabled(false);
            readcheck.setOpaque(false);
            readcheck.setText("I have read and accept the license agreement");
            readcheck.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    JCheckBox radioBtn = (JCheckBox)e.getSource();
                    if (radioBtn.isSelected())
                        okButton.setEnabled(true);                   
                    else
                        okButton.setEnabled(false);
            okButton.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    // TODO: whatever needs to be done here
            cancelButton.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    SwingUtilities.getWindowAncestor(contentPane).dispose();
            bottomPane.add(readcheck);
            bottomPane.add(okButton);
            bottomPane.add(cancelButton);
            contentPane.add(bottomPane);
            //readcheck.setVisible(false);
            contentPane.add(background);
        public JPanel getContentPane()
            return contentPane;
        public static void main(String[] args)
            EventQueue.invokeLater(new Runnable()
                public void run()
                    InstalleFrame install = new InstalleFrame();
                    JFrame frame = new JFrame("Install");
                    frame.getContentPane().add(install.getContentPane());
                    frame.setDefaultCloseOperation(3);
                    frame.setSize(550, 400);
                    frame.setUndecorated(false);  //**
                    frame.pack();  //**
                    frame.setLocationRelativeTo(null); //**
                    frame.setVisible(true);
    }

  • Obnoxious JTextPane and JScrollPane problem.

    I have written a Tailing program. All works great except for one really annoying issue with my JScollPane. I will do my best to explain the problem:
    The program will continue tailing a file and adding the text to the JTextPane. When a user scrolls up on the JScrollPane, the program still adds the text to the bottom of the JTextPane and the user can continue to view what they need.
    Here is the problem: I have text being colored throughout the text pane. For instance, the word ERROR will be in red. The problem is when the program colors the text, it moves the scroll pane to the line where word that was colored is at. I don't want that. If the user moves the scroll bar, I want the scroll bar to always stay there. I don't want the program to move to the text that was just colored.
    Is there a way to turn that off? I can't find anything like that anywhere.

    Coloring text will not cause the scrollpane to scroll.
    You must be playing with the caret position or something.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • JList(Vector) inside JScrollPane vanishes!

    Hi all, I have a problem thats driving me crazy, Im really stumped on this one;
    Im trying to update the GUI on a packet sniffer I wrote a while ago,
    I have a GUI class below as part of a larger program, this class containes a JList(Vector) inside a JScrollPane inside a JPanel inside a JFrame, I want this JList to be on the screen all the time, and grow dynamically as new elements are added to the Vector.
    Elements are added via an accessor method addPacket(Capture), you can assume the other classes in my program work fine.
    The problem is, the JFrame periodically goes blank, sometimes the scrollbars are present, sometimes not. After a while (sometimes) the JList reappears, containing the list of packets as it should, but it never lasts very long. Often it will disappear permanently.
    The class below is pretty short and simple, I really hope this is a simple and obvious mistake Ive made that someone can spot.
    Thanks,
    Soothsayer
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.InputStream;
    public class GUI extends JFrame
         Dimension screenResolution = Toolkit.getDefaultToolkit().getScreenSize();
         private InputStream fontStream = this.getClass().getResourceAsStream("console.ttf");
         Font outputFont;
         static final Color FIELD_COLOR = new Color(20, 20, 60);
         static final Color FONT_COLOR = new Color(150, 190, 255);
         private static JPanel superPanel = new JPanel();
         private static Vector<Capture> packetList = new Vector<Capture>(1000, 500);
         private static JList listObject = new JList(packetList);
         private static JScrollPane scrollPane = new JScrollPane(listObject);
         public GUI()
              super("LineLight v2.1 - Edd Burgess");
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setLocation(50, 10);
              try { outputFont = Font.createFont(Font.TRUETYPE_FONT, fontStream); }
              catch(Exception e) { System.err.println("Error Loading Font:\n" + e); }
              outputFont = outputFont.deriveFont((float)10);
              listObject.setFont(outputFont);
              superPanel.setPreferredSize(new Dimension(screenResolution.width - 100, screenResolution.height - 100));
              superPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
              scrollPane.setPreferredSize(new Dimension(screenResolution.width - 100, screenResolution.height - 100));
              scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
              scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
              scrollPane.setWheelScrollingEnabled(true);
              superPanel.add(scrollPane);
              this.add(superPanel);
              this.pack();
         public void addPacket(Capture c)
              this.packetList.add(c);
              this.listObject.setListData(packetList);
              this.superPanel.repaint();
    }

    I'm having basically the same problem, And how is your code different than the example in the tutorial???
    You can also read the tutorial section on "Concurrency".
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
    Start your own posting if you need further help.

  • JTextPane in JScrollPane... Scrolling when needed

    Hello all.
    I have a jtextpane in a jscrollpane and I'm using the following code to append a line in jtextpane and set the vertical scrollbar of jscrollpane at the bottom...
      htmlDoc = (HTMLDocument) output.getDocument();
      htmlKit.insertHTML(htmlDoc, htmlDoc.getLength(), s, 0, 0, null);
      output.setCaretPosition(htmlDoc.getLength());where output is the jtextpane.
    My problem is that, if the user manually changes the position of the vertical scrollbar, after appending a new line in jtextpane, the above code will set the scrollbar at the bottom.
    Is it possible to keep the scrollbar at the position it was before the new line has been appended (if the position of the scrollbar has been changed)?
    Thanks in advance,
    Charalampos

    StanislavL... with your suggestion the scroll bar will never scroll to the bottom.
    I want to place the scroll bar at the bottom if it was at the bottom before I append text to jtextpane, otherwise I want to leave the scroll bar at the same position it was before I append the text.

  • 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.

  • Help:Jtextpane in Jscrollpane , the vertical scroll bar  at bottom

    Immediate help needed if possible.
    The scrollpane that contains the textpane is showing the vertical bar at the bottom of the page even if use :-
    scrollRectToVisible(new Rectangle(0,0,1,1));
    Here is my code:-------------------------
    JPanel panel = new JPanel();
    JTextPane textPane = createTextPane();
    textPane.setEditable(false);
    textPane.scrollRectToVisible(new Rectangle(0,0,1,1));
    JScrollPane paneScrollPane = new JScrollPane(textPane);
    paneScrollPane.setPreferredSize(new Dimension(525, 285));
    paneScrollPane.setMinimumSize(new Dimension(14, 48));
    gc.addCentered(paneScrollPane);
    add ( panel );

    From
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2Btitle%3Ajtextpane+%2Btitle%3Atop&col=javaforums
    scrollRectToVisible(new Rectangle(0,0,1,1))

  • Drag/drop into JTable inside JScrollPane

    Hello,
    I have a table inside a JScrollPane. I can set the table as the DropTarget by the command:
    new DropTarget(table,fileDropTargetListener);
    but I cannot set the JScrollPane be the DropTarget by the same command.
    the problem is that: I cannot set the table to fit the JScrollPane by the command setsize(scrollPane.getSize() ), setPreferedSize(scrollPane.getPreferedSize()), (don't know for what reason, they don't work to fit the scrollpane), therefore when user drags an item to the JScrollPane but outside the table, the drag gesture doesnot display.
    Please anyone help me how to solve this problem. Thank you,
    fantabk

    Yes, I use custom cell renderer and cell editor for ParentTable, which returns NestedTable.
    DnD turned on for the ParentTable, so when the NestedTable is active (some cells selected in it) it receives DnD events, which are turned off for it, and DnD doesn't work.
    Possible solution is to turn DnD for NestedTable (not for ParentTable), and i'll do this if it is impossible to make it work in current configuration.
    So the question is � is this possible do not pass DnD event to NestedTable ?

  • FlowLayout fails to wrap inside JScrollPane

    I have a JPanel with FlowLayout inside a JScrollPane with the horizontal scrollbar disabled. I expect the FlowLayout to wrap the buttons in the example below but it doesn't.
    Could someone plase confirm this as a Swing bugg and perhaps suggest a workaround.
    Many Thanks!
    Patrik
    import java.awt.*;
    import javax.swing.*;
    public class WrapTest
       public static void main(String [] args)
          JFrame frame = new JFrame();
          JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
          panel.add(new JButton("xxxxxxxxxx"));
          panel.add(new JButton("xxxxxxxxxx"));
          panel.add(new JButton("xxxxxxxxxx"));
          panel.add(new JButton("xxxxxxxxxx"));
          frame.getContentPane().setLayout(new BorderLayout());
          frame.getContentPane().add(new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
             JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
          frame.setSize(400,300);
          frame.setVisible(true);
    }

    I think the policies controll whether the scrollbars are shown and not whether the JScrollPane is "scrollable". It's still a JScrollPane, whether you choose to display the scrollbars. If you don't want scrolling, I suggest useing a different component.
    I could be wrong on this. Someone please chime in if you disagree.

  • JLayeredPane inside JScrollPane - please help!!

    Hi everyone!
    i'm having the following problem: I need to add a JLayeredPane to a JScrollPane. this JLayeredPane contains a JGraph and this is what I'm doing:
      jlayeredPane = new JLayeredPane();
        jlayeredPane.add(graph, JLayeredPane.DEFAULT_LAYER);
        jlayeredPane.setPreferredSize(new Dimension(1000,1000));
        jlayeredPane.setMinimumSize(new Dimension(1000,1000));
        jsp = new JScrollPane(jlayeredPane);
       add(jsp);
    [/code
      but the graph doesn't show up at all. can anyone help me please. i have a deadline today and really need to figure this out. thanx a lot

    here's some of my code:
    inside the construtor of a panel
    graph = new Graph(new DefaultGraphModel(), new GraphLayoutCache());
        // JLayeredPane
        jlayeredPane = new JLayeredPane();
        // jlayeredPane.setMinimumSize(new Dimension(400,400));
        jlayeredPane.setPreferredSize(new Dimension(400, 400));
        jlayeredPane.add(graph, JLayeredPane.DEFAULT_LAYER);
        jsp= new JScrollPane(jlayeredPane); 
        jsp.addComponentListener(this);
        add(jsp, BorderLayout.CENTER);
    public void componentResized(ComponentEvent e) {
        int layeredPaneWidth = jlayeredPane.getWidth();
        int layeredPaneHeight = jlayeredPane.getHeight();
        int viewportwidth = jspLayered.getViewport().getWidth();
        int viewportheight = jspLayered.getViewport().getHeight();
        int width = Math.max(layeredPaneWidth, viewportwidth);
        int height = Math.max(layeredPaneHeight, viewportheight);
        jspLayered.getViewport().setSize(new Dimension(width, height));
        graph.setSize(width, height);
        graph.setPreferredSize(new Dimension(width, height));   
      }

  • ( (JTextPane in JScrollPane) in JTabbedPane)???

    JTextPane textarea = new JTextPane();
    JScrollPane scroll= new JScrollPane(textarea);
    JTabbedPane tab = new JTabbedPane();
    tab.add(scroll);
    Now the problem is when i create many tabs and put
    it in my window , and i want to jump from one tab to
    another , the textpane does not get the focus .
    tab contains scroll as its client so it gives focus to the
    scroll but i want the textarea to have the cursor.so that there is no need for the user to click in the textarea to gain focus.
    I hope some one understands my problem and helps me ...
    thanks alot......

    I'm running JDK1.3 on windows 98. The requestFocus() method does not work unless it is executed after the JFrame is shown. Maybe this is your problem. The following sample program will help illustrate this.
    1) run the program as is. Focus should be on the text area as you select a tab.
    2) Comment out the 'newTab' methods in the main method. Uncomment the 'newTab' methods in the constructor. This time focus will remain on the tab as you select it.
    Hope this helps.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class TestTabbedPane extends JFrame
         JTabbedPane tabbedPane;
         public TestTabbedPane()
              tabbedPane = new JTabbedPane();
              tabbedPane.setPreferredSize( new Dimension(300, 200) );
              getContentPane().add(tabbedPane);
    //          newTab( "one" );
    //          newTab( "two" );
    //          newTab( "three" );
         private void newTab(String text)
              JTextArea textArea = new JTextArea( text );
              JScrollPane scrollPane = new JScrollPane( textArea );
              tabbedPane.addTab( text, scrollPane );
              tabbedPane.setSelectedIndex( tabbedPane.getTabCount() - 1 );
              textArea.requestFocus();
         public static void main(String args[])
    TestTabbedPane frame = new TestTabbedPane();
    frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
    frame.pack();
    frame.setVisible(true);
              frame.newTab( "one" );
              frame.newTab( "two" );
              frame.newTab( "three" );

Maybe you are looking for