JTextArea , JScrollPane

how can i set the JScrollPane to the leftlower corner?i don't know how to use "field summery" in the API.
and how to add characters with different color into jtextarea?
thanks

I don't understand your problem about the
JScrollPanel. To place a Component where you want, you
can use GridBagLayout, BorderLayout, ... If you don't
know how to use them, e-mial me, I'll explain to you.
If you want change the plac of the scrool bars, you
can recuper them and place say they never beeen show
to the JScrollPane, and draw them yourself.
For differents Color, Font, background color to your
texte, use JTextPanehiya,
thank you for your reply,i will use jtextpane then.
about the jscrollpane.there is a test area in it, more and more information is added to it.i need the jscrollpane automatically display the button of the text area.it will be convenient for the user to read.they don't need to click the scrollbar then.
thanks

Similar Messages

  • Invisible JTextArea in a JScrollPane

    I want to have an invisible JTextArea in a JScrollPane (i only want a thin border either vieport border or JTextArea border). i tried setOpaque(false) for JTextArea, JScrollPane and both, and it wont work, i dont know why. Could anyone help me?

    This poster is 0 for 3 in responding to previous postings he has made.I did notice - that's why I didn't post the link.
    he/she might now learn how to do a search (for when future questions are ignored)
    What do you think the chances are he'll bother to thank anyone for the help
    he received on this posting?Nil
    a 'thank you' does go a long way to getting the next query answered, but I'd prefer just
    an acknowledement of "it works/doesn't work" - makes it so much easier, when
    searching the forums, when you spot a "yes, that works" at the end.

  • Console behavior for JScrollPane - - JTextArea

    I'm searching how to make a JScrollPane (containing a JTextArea) work like a console. By console, I mean the application user is FORCED to see the last message ( single line ) displayed in the text area at the moment it gets displayed.
    thanks for help,
    Pierre

    It's not necessary to answer, I found the solution :
    let's suppose :
    JTextArea view = new JTextArea();
    JScrollPane scrollPane = new JScrollPane( view );
    //THIS SINGLE LINE BRINGS THE TEXT AREA TO ITS LAST ROW
    scrollPane.getViewPort().setViewPosition(new Point(0, view.getHeigh()));
    et voil�, to whom it may help!
    Pierre

  • JTextArea in JScrollPane behaves strange

    Hello,
    in my Swing-UI I use a JTextArea which I embed into a JScrollPane.
    I use the setRows/setColumns methods to set the prefferedSize of the JTextArea which works nicely.
    However if the JTextArea is set to a smaller size than its preffered size (e.g by a JFrame resize) it becomes only 1 row height instead of using the JScrollPane to keep its size :-(
    Any ideas how this can be solved, would a screenshot help to understand the problem (sorry my english ins't really good).
    Thank you in advance, lg Clemens

    Hi again,
    If you spent any time answering questions on the
    forum then you should be aware that a high percentage
    of questions can be answer by simply refering the OP
    to the API or a tutorial of some kind. I spent many hours answering posts from other users, sometimes even guiding them through solutions step-by-step and I know what you're reffering to.
    Their are really lazy people araound, and I also posted one or two RTFM posts but only when I was absolutly sure that this question was asked many times or is explained in many tutorials.
    Just a reply like "layout manager?" would be enough, wouldn't it?
    So you're right, an executable testcase should be the best way to explain the problem.
    So here we go
    import java.awt.*;
    import javax.swing.*;
    public class SwingProblem extends JFrame
         public SwingProblem()
              JTextArea logText = logText = new JTextArea();
              JScrollPane logScroll = new JScrollPane(logText, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
              Container mainPanel = getContentPane();
              logText.setRows(10);
              mainPanel.setLayout(new GridBagLayout());
              mainPanel.add(logScroll, createConatraints(0, 1, 3, 4, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 100));
              this.pack();
              this.setVisible(true);
         protected GridBagConstraints createConatraints(int x, int y, int width, int height, int anchor, int fill, Insets insets, double weighty)
              GridBagConstraints gbc = new GridBagConstraints();
              gbc.anchor = anchor;
              gbc.gridx = x;
              gbc.gridy = y;
              gbc.gridwidth = width;
              gbc.gridheight = height;
              gbc.fill = fill;
              gbc.insets = insets;
              gbc.weightx = 1.0;
              gbc.weighty = weighty;
              return gbc;
         public static void main(String[] args)
              new SwingProblem();
    Any help would be greatly appriciated, thank you in advance.
    lg Clemens

  • Using JTextArea - How do I clear it?

    Hi all.
    I have written a GUI program which transfers data from a method to a JTextArea/JScrollPane upon a button ActionEvent.
    When I press the "Next Record" button I want to be able to clear the previous details held in this JTextArea before I print the new ones in it. The Same for going backwards through an array. Does anybody know how to do this?
    Currently I am using the append method to add the returned String to my JTextArea. I have also tried using a replaceRange(String, int, int) method to clear the box before printing new details, but this isn't working properly as each Record in the array contains a different String length, so I can not enter the int values for each specific object.
    Below is the code for the application, and I've highlighted where I have used the methods to add a String to the JTextArea. I'm declaring the class for the action event within creating the actionListener, but can seperate it out if people need to see it more clearly.
    RECORDING CLASS ----------
    package RecordingManagerGUI;
    public class Recording
    private String title, artist, genre;
         public Recording (String theTitle, String theArtist, String theGenre)
              title = theTitle;
              artist = theArtist;
              genre = theGenre;
            public String getAlbum()
                return title;
            public String getArtist()
                return artist;
            public String getGenre()
                return genre;
         public String toString()
              String s = "Title: " + title + "\nArtist: " + artist + "\nGenre: " + genre + "\n\n";
              return s;
    }MANAGER CLASS ---------------
    package RecordingManagerGUI;
    import java.util.*;
    public class Manager
    private Recording[] theRecordings;
    private int numRecordings, maxRecordings, age;
    private String managerName;
    //Extending the Manager Class Instance Variables
    private int current = 0;
    private String record;
         public Manager (String theName, int theAge, int max)
              managerName = theName;
                    age = theAge;
              maxRecordings = max;
              numRecordings = 0;
              theRecordings = new Recording[maxRecordings];
         public boolean addRecording (Recording newRecording)
              if (numRecordings == maxRecordings)
                   System.out.println("The store is full");
                   return false;
              else
                   theRecordings[numRecordings] = newRecording;
                   numRecordings++;
                   return true;
            public int nextRecording ()
                if(current < numRecordings)
                    current += 1;
                else
                    record = "You have reached the end of the Records"; //initialise the string if no records
                return current;
            public int previousRecording()
                if(current > 1)
                    current -= 1;
                else
                    record = "You have reached the start of the Records"; //initialise the string if no records
                return current;
            public String displayCurrent()
                String displayRec = "";
                displayRec += theRecordings[current-1];
                return displayRec;
         public void displayDetails()
              System.out.println("Manager Name: " + managerName + ", " + age);
         //public void displayRecordings()
         //     System.out.println("\nThe Recordings: ");
         //     for (int i = 0; i < numRecordings; ++i)
         //          System.out.println(theRecordings);
    }RecordingManagerGUI CLASS ----------/*
    *Need to add a Label which tells me when I have reached the end of the Records
    package RecordingManagerGUI;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class RecordingManagerGUI extends JFrame {
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    JButton nextRecord;
    JButton previousRecord;
    JLabel recordLabel;
    JTextArea displayRecord;
    Manager theManager;
    public RecordingManagerGUI() {
    //Create and set up the window.
    super("Recording Manager Application");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Recording FooFighters = new Recording("The Colour and the Shape", "Foo Fighters", "Rock");
    Recording BlindMelon = new Recording("Blind Melon", "Blind Melon", "Alternative Rock");
    Recording JoeSatriani = new Recording("The Extremist", "Joe Satriani", "Instrumental Rock");
    Recording PercySledge = new Recording("When a Man Loves a Woman", "Percy Sledge", "Soul");
    Recording JustinTimberlake = new Recording("Justified", "Justin Timberlake", "Pop");
    Recording BeyonceKnowles = new Recording("Dangerously in Love", "Beyonce Knowles", "R'n'B");
    Recording TupacShakur = new Recording("2Pacalypse Now", "Tupac Shakur", "Hip Hop");
    theManager = new Manager("Cathy", 42, 7);
    theManager.addRecording(FooFighters);
    theManager.addRecording(BlindMelon);
    theManager.addRecording(JoeSatriani);
    theManager.addRecording(PercySledge);
    theManager.addRecording(JustinTimberlake);
    theManager.addRecording(BeyonceKnowles);
    theManager.addRecording(TupacShakur);
    displayRecord = new JTextArea(10, 30);
    displayRecord.setEditable(false);
    JScrollPane recordScroll = new JScrollPane(displayRecord);
    recordLabel = new JLabel("Record Details");
    nextRecord = new JButton("Next Record");
    nextRecord.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){theManager.nextRecording();displayRecord.append(theManager.displayCurrent());displayRecord.replaceRange(theManager.displayCurrent(), 0, 30);}}); //ADDING STRING TO JTEXTAREA
    previousRecord = new JButton("Previous Record");
    previousRecord.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){theManager.previousRecording();displayRecord.replaceRange(theManager.displayCurrent(), 0, 30);}}); //ADDING STRING TO JTEXTAREA
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(recordLabel);
    getContentPane().add(recordScroll);
    getContentPane().add(nextRecord);
    getContentPane().add(previousRecord);
    //Display the window.
    pack();
    setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    new RecordingManagerGUI();
    }Would appreciate any help thanks. I'm not sure if I just need to create a new instance of the JTextArea upon the event which would hold the String information. If so I'm not really sure how to do this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I don't know, the Swing experts are in the Swing forum. but setText() is defined in TextComponent, which a JTextArea is.

  • Word wrap with JScrollPane

    Quick question. Trying to get word wrap in a JTextField
    using JSrollPane. Below is a small snippet of code
    from my program...
    displayArea = new JTextArea ( );
    JScrollPane scroll = new JScrollPane ( displayArea,
       JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
       JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); Doesn't using JScrollPane.HORIZONTAL_SCROLLBAR_NEVER automatically
    introduce word wrap? I'm not getting it in my program. Somebody please correct me. Thanks!

    displayArea.setLineWrap (true);
    displayArea.setWrapStyleWord (true);I thought it wasn't added automatic.
    Kind regards,
      Levi

  • How to select multiple substring in JTextarea at the same time?

    I want to select multiple substring in a jtextarea at the same time by select(start,end) method, turns out only the last substring is highlighted, how to implement my goal?

    jamesybaby wrote:
    What you got so far? A SCCEE would be nice?my aim is to search key words in jtextarea and highlight all matched result.
    package frame;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class FrmSelect extends JFrame {
        public FrmSelect() throws HeadlessException {
            setSize(800, 600);
            final JTextField tfKey = new JTextField();
            tfKey.setPreferredSize(new Dimension(200, 20));
            final JTextArea taContent = new JTextArea();
            JScrollPane jsp = new JScrollPane(taContent);
            tfKey.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    String key = tfKey.getText();
                    String content = taContent.getText();
                    String[] splited = content.split(key);
                    Pattern ptn = Pattern.compile(key, Pattern.CASE_INSENSITIVE + Pattern.MULTILINE);
                    Matcher matcher = ptn.matcher(content);
                    taContent.requestFocusInWindow();
                    while (matcher.find()) {
                        int start = matcher.start();
                        int end = matcher.end();
                        taContent.select(start, end);
            add(tfKey,BorderLayout.SOUTH);
            add(jsp,BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        public static void main(String[] args) {
             new FrmSelect();
    }please copy below into the jtextarea and type key 'prop' in the jtextfield, press return.
    prop1adsfasfd
    prop2adsfasdfadsf
    prop3asdfasdfasdf

  • HTML TextArea is a  JScrollPane in JEditorPane?

    Hi all,
    I'm trying to create an autofill facility for my application, to do this I am getting the components from the HTML document and converting them to their Java Swing counterpart.
    So for example <input type="text" name="example" /> would be a normal text input field on a HTML form, and its Swing conversion is a JTextField - this works as desired and it allows me to use the .settext() command to set the text on the HTML form - i.e. autofilling.
    My problem comes when I try to get the component for a HTML textarea, e.g. <textarea name="example"></textarea> - I would expect the Swing component to be a JTextArea, but the class it gets converted to is a JSrcollPane! This leads to a problem as I can't set the text of a JScrollPane as it is a container.
    Does anyone know how I might get around this problem so that I can set the text for the textarea? I've included my code below.
    Many thanks
    BBB
    import java.awt.event.*;
    import java.awt.*;
    import java.net.URL;
    import javax.swing.*;
    public class Tester extends JFrame{
        static JEditorPane pane = new JEditorPane();
        public Tester()
            try {
                pane.setPage( new URL("http://www.amray.com/cgi/amray/addurl.cgi") );
            } catch (Exception e) {
            this.getContentPane().add(new JScrollPane(pane));
            JButton b1 = new JButton("Auto Fill");
            this.getContentPane().add(b1,BorderLayout.SOUTH);
            b1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                    for ( int i = 0; i < pane.getComponentCount(); i++ )
                        Container c = (Container)pane.getComponent(i);
                        Component swingComponentOfHTMLInputType = c.getComponent(0);
                        System.out.println(swingComponentOfHTMLInputType.getClass());
                        if ( swingComponentOfHTMLInputType instanceof JTextField ) {
                            JTextField tf = (JTextField)swingComponentOfHTMLInputType;
                            tf.setBackground( Color.yellow );
                            tf.setText("Auto Filled");
                        if ( swingComponentOfHTMLInputType instanceof JScrollPane ) {
                            JScrollPane ta = (JScrollPane)swingComponentOfHTMLInputType;
        public static void main(String args[]) {
            Tester app = new Tester();
            app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            app.setSize( 400, 400 );
            app.setVisible( true );
    }

    Hi Jim,
    Thanks for the suggestion, but I've already tried that and although it does work from a visual POV, when you then submit the form the data in the JTextArea isn't added - it just says the field is blank.
    Although, I'm not sure whether it's not working due to the method I've had to use to add the JTextArea: -
    JScrollPane ta = (JScrollPane)swingComponentOfHTMLInputType;
    JTextArea oTextArea = new JTextArea();
    oTextArea.setText("Hello World!");
    ta.setViewportView(oTextArea);I'm not sure if it's not working because I've had to use .setViewportView(); rather than .add(). If I use .add() then no changes are reflected on screen and the JTextArea isn't actually added.
    Any other suggestions?

  • Layout for JTextArea

    I want to develop an application that is having a message window, through which I can be able to send message. The window should have a "Send" button, one "To" textfield, one "Subject" textfield and one textarea with scrolls as needed.
    I am not getting the exact layout for placing the components.
    If anybody can help me writing the code , I shall be grateful .
    Regards.

    import java.awt.*;
    import javax.swing.*;
    public class TEST extends JFrame
         public TEST()
              Container cp = getContentPane();
              cp.setLayout(new BorderLayout());
              JPanel p1 = new JPanel();
              p1.setLayout(new GridLayout(2,1,4,4));
              JPanel p2 = new JPanel();
              p2.add(new JLabel("To"));
              p2.add(new JTextField(20));
              JPanel p3 = new JPanel();
              p3.add(new JLabel("Subject"));
              p3.add(new JTextField(20));
              p1.add(p2);
              p1.add(p3);
              cp.add(p1, BorderLayout.NORTH);
              int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
              int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
              JTextArea ta = new JTextArea();
              JScrollPane jsp = new JScrollPane(ta,v,h);
              cp.add(jsp);
              p1 = new JPanel();
              p1.add(new JButton("Send"));
              cp.add(p1, BorderLayout.SOUTH);
         public static void main(String ar[])
              TEST t = new TEST();
              t.setSize(400,300);
              t.setVisible(true);
    }

  • How to implement Line number in JTextArea

    Hi
    I have seen some JTextArea with Line numbers How to do it
    Thankx

    I'm playing around with trying to make a Line Number component that will work with JTextArea, JTextPane, JTable etc. I'm not there yet, but this version works pretty good with JTextArea. At least it will give you some ideas.
    Good luck.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.text.*;
    public class LineNumber extends JComponent
         private final static Color DEFAULT_BACKGROUND = new Color(230, 163, 4);
         private final static Color DEFAULT_FOREGROUND = Color.black;
         private final static Font DEFAULT_FONT = new Font("monospaced", Font.PLAIN, 12);
         // LineNumber height (abends when I use MAX_VALUE)
         private final static int HEIGHT = Integer.MAX_VALUE - 1000000;
         // Set right/left margin
         private final static int MARGIN = 5;
         // Line height of this LineNumber component
         private int lineHeight;
         // Line height of this LineNumber component
         private int fontLineHeight;
         private int currentRowWidth;
         // Metrics of this LineNumber component
         private FontMetrics fontMetrics;
         *     Convenience constructor for Text Components
         public LineNumber(JComponent component)
              if (component == null)
                   setBackground( DEFAULT_BACKGROUND );
                   setForeground( DEFAULT_FOREGROUND );
                   setFont( DEFAULT_FONT );
              else
                   setBackground( DEFAULT_BACKGROUND );
                   setForeground( component.getForeground() );
                   setFont( component.getFont() );
              setPreferredSize( 9999 );
         public void setPreferredSize(int row)
              int width = fontMetrics.stringWidth( String.valueOf(row) );
              if (currentRowWidth < width)
                   currentRowWidth = width;
                   setPreferredSize( new Dimension(2 * MARGIN + width, HEIGHT) );
         public void setFont(Font font)
              super.setFont(font);
              fontMetrics = getFontMetrics( getFont() );
              fontLineHeight = fontMetrics.getHeight();
         * The line height defaults to the line height of the font for this
         * component. The line height can be overridden by setting it to a
         * positive non-zero value.
         public int getLineHeight()
              if (lineHeight == 0)
                   return fontLineHeight;
              else
                   return lineHeight;
         public void setLineHeight(int lineHeight)
              if (lineHeight > 0)
                   this.lineHeight = lineHeight;
         public int getStartOffset()
              return 4;
         public void paintComponent(Graphics g)
              int lineHeight = getLineHeight();
              int startOffset = getStartOffset();
              Rectangle drawHere = g.getClipBounds();
    //          System.out.println( drawHere );
    // Paint the background
    g.setColor( getBackground() );
    g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);
              // Determine the number of lines to draw in the foreground.
    g.setColor( getForeground() );
              int startLineNumber = (drawHere.y / lineHeight) + 1;
              int endLineNumber = startLineNumber + (drawHere.height / lineHeight);
              int start = (drawHere.y / lineHeight) * lineHeight + lineHeight - startOffset;
    //          System.out.println( startLineNumber + " : " + endLineNumber + " : " + start );
              for (int i = startLineNumber; i <= endLineNumber; i++)
                   String lineNumber = String.valueOf(i);
                   int width = fontMetrics.stringWidth( lineNumber );
                   g.drawString(lineNumber, MARGIN + currentRowWidth - width, start);
                   start += lineHeight;
              setPreferredSize( endLineNumber );
         public static void main(String[] args)
              JFrame frame = new JFrame("LineNumberDemo");
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              JPanel panel = new JPanel();
              frame.setContentPane( panel );
              panel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
              panel.setLayout(new BorderLayout());
              JTextArea textPane = new JTextArea();
              JScrollPane scrollPane = new JScrollPane(textPane);
              panel.add(scrollPane);
              scrollPane.setPreferredSize(new Dimension(300, 250));
              LineNumber lineNumber = new LineNumber( textPane );
              lineNumber.setPreferredSize(99999);
              scrollPane.setRowHeaderView( lineNumber );
              frame.pack();
              frame.setVisible(true);

  • JScrollPane will not appear

    I'm trying to add a scroll bar to a JTextArea. The textarea appears but there is no scroll bar.
    Here's what I'm doing. I've included the whole class in case there is something relevant that I don't realise. Any ideas on what I'm doing wrong?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Basic extends JFrame
    JTextArea output;
         public Basic()
              super( "Diagram" );
              setSize( 800, 600 );
              Container c = getContentPane();
              JMenuBar bar = new JMenuBar();          
              JMenu fileMenu = new JMenu( "File" );
              JMenuItem n = new JMenuItem( "New" );
              JMenuItem open = new JMenuItem( "Open" );
              JMenuItem close = new JMenuItem( "Close" );
              JMenuItem save = new JMenuItem( "Save" );
              JMenuItem create = new JMenuItem( "Create Diagram" );     
              fileMenu.add(n);
              fileMenu.add(open);
              fileMenu.add(close);
              fileMenu.add(save);
              fileMenu.add(create);
              bar.add(fileMenu);
              output = new JTextArea();
              JScrollPane scroll = new JScrollPane(output);
              n.addActionListener(
                   new ActionListener()
                   {public void actionPerformed( ActionEvent e)
                        OpenUI o = new OpenUI();
                        TokenTest t = new TokenTest(o.fileText, output);
              c.add(bar, BorderLayout.NORTH);
              c.add(scroll);
              show();          
    }

    Use the methods SetVerticalScrollbarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS) and
    SetHorizontalScrollbarPolicy(HORIZONTAl_SCROLLBAR_ALWAYS) so the scrollbars will appear whether they are needed or not.
    OR
    use new JTextArea(40,100) to set the minimum rows and columns of the textarea.

  • Simple quesiton on JTextArea, scroll bar

    HI, all java programmers, i think my question is simple...pls help ...
    I use the following coding to add a scrollable textarea to my JPanel , panelSouth.
    details = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(details,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    panelSouth.add( scrollPane, BorderLayout.CENTER );
    i wanna to append text to the text area.
    i use details.append("my text");
    however, any method can scrol down the text area? so that my new text can be
    shown automatically when a new text was added?
    the scrol bar won't scroll down when i add text.
    if i add a large amount of text.. user
    need to scrol down to see the newest text..
    and also, user , may not know some new text was added...
    thx all experts...
    yours,
    terry

    details.setCaretPosition(details.getText().length());
    Noah

  • JTextArea not showing

    I can get my first set of JScrollPane and JTextArea to appear, but the second just will not. Here is all my code refering to the frame. I hope you can find what I cannot.
            public Frame(){
                Object[] items={"Choose One","1","2","3","4","5","6","7","8","9","10"};
                JPanel c=(JPanel)getContentPane();
                JOptionPane jOpt=new JOptionPane();
                ImageIcon icon=new ImageIcon();
                jArea=new JTextArea();
                JScrollPane jScroll=new JScrollPane(jArea);
                jArea2=new JTextArea();
                JScrollPane jScroll2=new JScrollPane(jArea2);
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                setSize(new Dimension(250, 500));
                setTitle("Towers Of Hanoi");
                //setResizable(false);
                setLocationRelativeTo(null);
                jScroll.setPreferredSize(new Dimension(125, 500));
                jScroll.setPreferredSize(new Dimension(125,500));
                jScroll.setViewportView(jArea);
                jScroll2.setViewportView(jArea2);
                c.setLayout(new BorderLayout());
                c.add(jOpt);
                jOpt.setVisible(false);
                c.add(jScroll, java.awt.BorderLayout.WEST);
                c.add(jScroll2, java.awt.BorderLayout.EAST);
                jScroll2.setVisible(true);
                boolean done=false;
                String s="";
                while(done==false){
                    s=(String)jOpt.showInputDialog(this,"How many disks should be used?","",jOpt.PLAIN_MESSAGE,icon,items,"Choose One");
                    if(!s.equals("Choose One"))
                        done=true;
                height=Integer.parseInt(s);
                show();
            }//Close Frame Constructor

    maybe
    setLocationRelativeTo(null);
    jScroll.setPreferredSize(new Dimension(125, 500));
    jScroll.setPreferredSize(new Dimension(125,500));//should be jScroll2.setPreferredSize(...)
    jScroll.setViewportView(jArea);

  • How do I remove the inside border in a JScrollPane?

    I'm trying to embed a JTextArea inside a JScrollPane. Not sure if it matters, but the JScrollPane is inside a JSplitPane, i. e.
    JSplitPane js = new JSplitPane(...)
    JTextArea ta = new JTextArea();
    JScrollPane sp = new JScrollPane(ta);
    js.setBottomComponent(sp);Now when the whole thing is seen, a black border is drawn around the TextArea ta. How do I remove this? Doing sp.setViewportBorder(null) doesn't help. Please help! THX.
    Edited by: solletica on Jun 10, 2008 8:45 AM
    Edited by: solletica on Jun 10, 2008 8:50 AM

    The problem is seen ONLY when the neither scrollbar is visible, i. e. when the AS_NEEDED property is set on JScrollPane. When this happens, a black square border is visible around the JTextArea.
    However, when the vertical or horizontal scrollbars are shown, the portion of the border where the scrollbar appears isn't visible (or noticeable).
    Correct me if I'm wrong, but doesn't JComponent.setBorder() only set the OUTSIDE border of a JComponent? I want to eliminate the border being shown around the JTextArea (i. e. between the JTextArea's bounds and the JScrollPane).
    Edited by: solletica on Jun 10, 2008 9:24 AM

  • Scrolling in JtextArea ????

    Can anybody tell me how to introduce scrolling in JtextArea ???
    Following is the skeleton of my code ...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;         
    import java.io.*;
    public class Interface extends Frame
                 String path;
                 JTextField text = new JTextField();
         JButton button = new JButton("Browse");
         JButton executeButton = new JButton("Execute");
         JTextArea area = new JTextArea();
         JPanel P1 = new JPanel();
            public Component createComponents()
                        text.setBounds(30,30,300,20);
                 button.setBounds(30,70,80,20);
                         executeButton.setBounds(130,70,80,20);
                         area.setBounds(30,110,540,430);
                    P1.setBackground(Color.red);
                    P1.setLayout(null);
                 P1.add(button);
                 P1.add(executeButton);
                 P1.add(text);
                    P1.add(area);
                 return P1;
             public static void main(String[] args)
                 JFrame frame = new JFrame("Pseudocode Interpreter");
                 Interface app = new Interface();
                 Component contents = app.createComponents();
                 frame.getContentPane().add(contents);
                    frame.setSize(600,600);
                    frame.setVisible(true);
                    frame.setLocation(50,50);
                         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }Thanks !!!!

    I am happy to help use but addind scroll pane is a simple one.
    y not u post it in swing ya?.
    you can add scrollpane by
    JScrollPane jsp=new JScrollPane(new JTextArea(20,20));
    yourpanel.add(jsp);
    if u still have problem post. u r welcome.
    i did not run the below changed code u may try it.it is so simple.....
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class Interface extends Frame
         String path;
         JTextField text = new JTextField();
         JButton button = new JButton("Browse");
         JButton executeButton = new JButton("Execute");
         JTextArea area = new JTextArea();
    JScrollPane jsp=new JScrollPane(area);
         JPanel P1 = new JPanel();
    public Component createComponents()
         text.setBounds(30,30,300,20);
         button.setBounds(30,70,80,20);
         executeButton.setBounds(130,70,80,20);
         jsp.setBounds(30,110,540,430);
         P1.setBackground(Color.red);
         P1.setLayout(null);
         P1.add(button);
         P1.add(executeButton);
         P1.add(text);
         P1.add(jsp);
         return P1;
         public static void main(String[] args)
         JFrame frame = new JFrame("Pseudocode Interpreter");
         Interface app = new Interface();
         Component contents = app.createComponents();
         frame.getContentPane().add(contents);
         frame.setSize(600,600);
         frame.setVisible(true);
         frame.setLocation(50,50);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

Maybe you are looking for

  • How can I copy the SMS from my Nokia 6303 to a Sam...

    Hello everybody! I just bought a Samsung Galaxy S4 mini...and I find such a pity to lose all the SMS that I had in my Nokia 6303. The new phone is sim-locked so unfortunately I cannot copy the SMS that way. Does anyone know if there is a possibility

  • SDDM Beta 3.3 trigger code generation

    If you are generating PL/SQL trigger code in Oracle 11gR2 you can replace the following the SQL SELECT statement with a straight next value sequence number assignment. It is cleaner, easier to read and debug. ---- old way start CREATE OR REPLACE TRIG

  • TDS UTILITY NOT WORKING

    HI I am upgrading the SAP B1 2007B to SAP B1 8.8, I have download the  TDS upgrade utility But cannot able to run , i am getting the following error. The version of this file is not compatible with the version of windows you are running. check your c

  • Import error for .prproj files

    so i've just touched adobe mc CS4 for the first time, my church is allowing me to use the studio/editing room while not being used during the day at certain times. i am compiling a dvd of my wedding to make it more proffessional than the previously m

  • Dreadfully slow when trying to mousedrag an image

    Hi. I just switched to Keynote '09 and am trying to edit a very simple, one slide diagram that I created in Keynote '08. Whereas moving a single image around in '08 is seamless, moving the same image in the '09 version of the files is PAINFULLY slow,