GUI. puting JScrollPanel in JTextArea component

Hi. how can I pus JScrollPanel in JTextArea component rigt. that JScrollPanel would be wisable and usable???
JTextArea is in JPanel(Layout = null), Jvanes is in Container
        Container con = getContentPane();
        pagr = new JPanel();
        con.add(pagr);JTextArea has to be in pagr.
maybe someone has any suggestions?
        try {                      
            jbInit();             
        } catch (Exception ex) { 
            ex.printStackTrace();
    private void jbInit() throws Exception {
        pagr.setLayout(null);
        txt.setBounds(new Rectangle(10, 10, 475, 440));
        filtr.setBackground(UIManager.getColor("Button.disabledForeground"));
        filtr.setBounds(new Rectangle(490, 375, 185, 75));
        pasir.setBackground(new Color(230, 230, 230));
        pasir.setSelectionBackground(Color.blue);
        pasir.setSelectionForeground(Color.orange);
        pasir.setBounds(new Rectangle(490, 10, 185, 355));
        txt.setBackground(new Color(230, 230, 230));
        txt.setSelectedTextColor(Color.red);
        txt.setSelectionColor(Color.lightGray);
        pagr.setBackground(Color.lightGray);
        scrl = new JScrollPane(txt);
        scrl.setEnabled(true);
        scrl.setVisible(true);
        pagr.add(txt);
        pagr.add(filtr);
        pagr.add(pasir);
    }txt i JTextArea component.
not working, also Designer Mesages box throws:
Failed to create live value from JScrollPane scrl = null;: null
Failed to create live visual subcomponent (scrl) as javax.swing.JScrollPane; creating a red component in its place

I'm using null Layout that I would be able to pusall
components where I want. prefering size umeanfiltr.setBounds(new Rectangle(490, 375, 185,
75));
and JScrollPane is subComponent of txt, atleast I want to to describe it that way.Did you miss my comment? You are adding text to the
scrollpane but you are not adding the scroll pane
anywhere. Also I would highly recommend that you use
layout managers.
    JTextArea txt = new JTextArea(13,30);
    JScrollPane scrl = null;
    JList pasir = new JList();
    JButton filtr = new JButton("Filtruoti");
    JPanel pagr;
//skiped some of code
    public Pradzia() {
        Container con = getContentPane();//              <--geting container
        pagr = new JPanel();
        con.add(pagr);//adding JPanel to con
//skiped some of code
        try {                      
            jbInit();             
        } catch (Exception ex) { 
            ex.printStackTrace();
    private void jbInit() throws Exception {
        pagr.setLayout(null);
        txt.setBounds(new Rectangle(10, 10, 475, 440));
        filtr.setBackground(UIManager.getColor("Button.disabledForeground"));
        filtr.setBounds(new Rectangle(490, 375, 185, 75));
        pasir.setBackground(new Color(230, 230, 230));
        pasir.setSelectionBackground(Color.blue);
        pasir.setSelectionForeground(Color.orange);
        pasir.setBounds(new Rectangle(490, 10, 185, 355));
        txt.setBackground(new Color(230, 230, 230));
        txt.setSelectedTextColor(Color.red);
        txt.setSelectionColor(Color.lightGray);
        pagr.setBackground(Color.lightGray);
        scrl = new JScrollPane(txt);//                  <--ading JScrollPane to txt(JTextArea)
        scrl.setEnabled(true);
        scrl.setVisible(true);
        pagr.add(txt);//                              <--adding txt to pagr(JPanel)
        pagr.add(filtr);
        pagr.add(pasir);
or I don't understand something.

Similar Messages

  • Text printing in JtextArea component

    I have created a swing application In which i have used Jtextarea component to print output using thread. To write output i m using append method. When thread print the output in text area it is appended but to see these output I need always to sroll the page,
    Is there any way that when output is printed it should be appeared on screen at lower portion of text editor.

    I have use the following code but it is very slow
    logTextArea.append("your text");
    logTextArea.setCaretPosition( logTextArea.getDocument().getLength() );

  • How to paste information onto the JTextArea component?

    First of all, thank you for your concernding. The problem that i have is trying to copy information from the MS-WORD to the JTextArea component. When i right_clicked the mouse onto the JTextArea component, it wouldn't let me do the pasting.
    Please, Help!!!!

    hi,
    have you tried ctrl-c to copy and then ctrl-v to paste?

  • Moving the Focus with the TAB key in a JTextArea Component

    Dear Friends,
    I have exhausted all options of moving focus from JTextArea to next component. I have also tried all suggestions available in this forum. But i'm not able to solve my problem. Can any one help me.
    Thanx in advance.

    I had the same problem before. Here is what i did.
    JTextArea txtArea = new JTextArea(2,15);
    Set forwardTraversalKeys = new HashSet();     
    forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));          
    txtArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,forwardTraversalKeys);          
    Set backwardTraversalKeys = new HashSet();          
    backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));          
    txtArea.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardTraversalKeys);
    JScrollPane scrollPane = new JScrollPane(
         txtArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // the scrollbar of the JScrollPane is focusable that's why it requires
    // another TAB key to transfer the focus.
    scrollPane.getVerticalScrollBar().setFocusable(false);

  • How can I assign a text file to JTextArea component??

    Hi every body, does any boody has a code for read a text file and show this text in a JTextArea??? I'm trying with a FileReader but the text doesn't appear well.
    Thanks in advance.
    Juan

    String s = "";
    BufferedReader reader =
                             new BufferedReader(new FileReader(path));
                        String temp = reader.readLine();
                        s += temp + "\n";
                        while (temp != null)
                             temp = reader.readLine();
                             if (temp != null)
                                  s += temp + "\n";
                        reader.close();
    textArea.setText(s);

  • Customize "Tab" key for JTextArea to focus next component.

    Hi,
    I am trying to change the "TAB" key behaviour for JTextArea, by using CustomAction configured via InputMap() and ActionMap(). When the user presses the Tab key, the focus should go the next component instead of tabbing in the same JTextArea component. Here is the code for the CustomAction().
        public static class CustomTabAction extends AbstractAction {
            private JComponent comp;
            public CustomTabAction (JComponent comp) {
                this.comp = comp;
                this.comp.getInputMap().put(KeyStroke.getKeyStroke("TAB"), "TABPressed");
                this.comp.getActionMap().put("TABPressed", this);
            public void actionPerformed(ActionEvent evt) {
                Object source = evt.getSource();
                if (source instanceof Component) {
                    FocusManager.getCurrentKeyboardFocusManager().
                            focusNextComponent((Component) source);
        }This works for most of the cases in my applicaiton. The problem is that it doesn't work with JTable which has a custom cell editor (JTextArea). In JTextArea field of JTable, if the Tab is pressed, nothing happens and the cursor remains in the custom JTextArea exactly at the same place, without even tabbing spaces. Here is the CustomCellEditor code.
        public class DescColCellEditor extends AbstractCellEditor implements TableCellEditor {
    //prepare the component.
            JComponent comp = new JTextArea();
            public Component getTableCellEditorComponent(JTable table, Object value,
                    boolean isSelected, int rowIndex, int vColIndex) {
                // Configure Tab key to focus to next component
                CustomActions.setCustomAction("CustomTabAction", comp);
                // Configure the component with the specified value
                ((JTextArea)comp).setText((String)value);
                // Return the configured component
                return comp;
            // This method is called when editing is completed.
            // It must return the new value to be stored in the cell.
            public Object getCellEditorValue() {
                return ((JTextArea)comp).getText();
        }regards,
    nirvan

    >
    textArea.getInputMap().remove(....);but that won't work because the binding is actually defined in the parent InputMap. So I think you need to use code like:
    textArea.getInputMap().getParent().remove(...);But I'm not sure about this as I've never tried it.I tried removing the VK_TAB key from both the input map and parent input map as shown below. But I still have to press "TAB" twice in order to get out of the JTextArea column in JTable.
                comp.getInputMap().getParent().remove(
                            KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));
                comp.getInputMap().remove(
                            KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0));after coding this, I am using the setFocusTraversalKeys for adding only "TAB" key as ForwardTraversalKey as given below.
            Set newForwardKeys = new HashSet();
            newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
            comp.setFocusTraversalKeys(
                        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,newForwardKeys);
            Set newBackwardKeys = new HashSet();
            newBackwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK));
            comp.setFocusTraversalKeys(
                        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,newBackwardKeys);The only problem that remains now is that I have to press the "TAB" twice in order to get out of the JTextArea column
    regards,
    nirvan.

  • Updating a GUI component

    Hello,
    My application has an output window with a JTextArea as one of the components. This window is instantiated when the application starts up. What would be the best way to update the JTextArea component with the messages (status reports) generated by the other classes. What technique should I employ in this regard?
    Thank You.

    Here is my idea:
    I do not think it is a good design to pass textArea to any components
    that need to report the status message.
    It is may-be better using proxy design.
    Let's say, created a StatusManager class.
    The status manager can have different constructors,
    for example constructor with textarea as parameter,
    or other constuctor with outputsteam as parameter ...etc.
    And you pass the StatusManager to any components that needed to report the status message.
    In this way, all components just use StatusManager's method to report the message,
    and StatusManager can control the synchronized of message, the "output" of message
    ( to textarea or file ), and may-be also reformat the message.
    In fact, have one layer between the source ( components report message ) and the real destination
    ( your textarea), it will become more flexible ( esay to change in the future) and esay to maintenance.
    If you like this idea, you can even make more generic, like create your own listener interface,
    any component (the destination part) can implement the listener and register to the StatusManager
    in the way, you can even report to multi-destination.
    Just my thought.

  • Building a customized gui component

    I wud like to know, how can I make my own gui components in Java.
    Are there some classes which help in this thing.
    And if not, how difficult is it to make your own gui components?

    Is the component you want to create similar to an existing component ? If so, extend that component.
    If not, look at the API and see what classes existing components extend and then extend whichever of those is most suitable.
    For a Swing component, JComponent is probably a good place to start.
    For an AWT component, try Component.
    I would imagine the gui tutorials are probably worth reading as well.

  • GUI--- jTextArea

    i am using a gui frame and a jTextArea on the frame. I need to ask the user a question and put it in the jTextArea using the append() method. But how to I get their input that they write in the jTextArea and store it in a String variable?

    Ah, so you do know how to use your login to post again. I wonder why you don't post some kind of follow-up on your other thread. Usually I shy away from talking to people who ask me a question, I answer them, and they don't even have the common courtesy to say "thanks".
    http://forum.java.sun.com/thread.jspa?threadID=613781

  • How can I update a JTextArea from another class

    I am new to Java so forgive me if this is confusing, or if I seem to be taking an overly complex route to acheiving my goal.
    I've got a JTextArea component added to a JPanel object, which is then inserted into the JFrame. I have a JMenuBar with a JMenu "file" and a JMenuItem "connect" on this same JFrame. When clicked, the actionEvent of JMenuItem "connect" calls a class "ConnectToDb" to establish a connection with the Database. On a successful connection, I want to append the String "Connection Successful" to the JTextArea component, but since the component is a part of the JPanel object, I cannot seem to get access to the JTextArea component to update it. I tried instantiating the JPanel object from within the "ConnectToDb" class and then called a method I created to set the JTextArea. No luck. Can someone give me an idea of what I need to do that would allow me to update the text of the JTextArea component from anywhere in my program? Once it has been contained in the JPanel or JFrame, can it be updated?
    This is the class that establishes the simple Db Connection
    package cjt;
    import java.io.*;
    import java.sql.*;
    * Get a database connection
    * Creation date: (04/01/2002 4:08:39 PM)
    * @author: Yaffin
    public class ConnectToDB {
    public Connection dbConnection;
    // ConnectToDB constructor
    public ConnectToDB() {
    public Connection DbConnect() {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String sourceURL = new String("jdbc:odbc:CJTSQL");
    Connection dbConnection = DriverManager.getConnection(sourceURL, "Encryptedtest", "pass");
    System.out.println("Connection Successful\n");
    //this is where I originally tried to append "Connection Successful
    //to the JTextArea Object in WelcomePane()          
    } catch (ClassNotFoundException cnfe) {
    //user code
    System.out.println("This ain't working because of a class not found exeption/n");
    } catch (SQLException sqle) {
    //user code
    System.out.println("SQL Exception caused your DB Connection to SUCK!/n");
    return dbConnection;
    This is the JPanel that contains the JTextArea "ivjStatusArea" I am trying to update from other classes. Specifically the "ConnectToDb" class above.
    package cjt;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    * Build Welcome Pane
    * Creation date: (04/01/2002 3:42:50 PM)
    * @author: yaffin
    public class WelcomePane extends JPanel {
         private JTextArea ivjtxtConnect = null;
         private JLabel ivjwelcomeLbl = null;
         private JTextArea ivjStatusArea = null;
    * WelcomePane constructor comment.
    public WelcomePane() {
         super();
         initialize();
    * Return the StatusArea property value.
    * @return javax.swing.JTextArea
    private javax.swing.JTextArea getStatusArea() {
         if (ivjStatusArea == null) {
              try {
                   ivjStatusArea = new javax.swing.JTextArea();
                   ivjStatusArea.setName("StatusArea");
                   ivjStatusArea.setLineWrap(true);
                   ivjStatusArea.setWrapStyleWord(true);
                   ivjStatusArea.setBounds(15, 153, 482, 120);
                   ivjStatusArea.setEditable(false);
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjStatusArea;
    * Initialize the class.
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("WelcomePane");
              setLayout(null);
              setSize(514, 323);
              add(getStatusArea(), getStatusArea().getName());
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    This is the main class where evrything is brought together. Notice the BuildMenu() method where the JMenuItem "connect" is located. Also notice the PopulateTabbedPane() method where WelcomePane() is first instantiated.
    * The main application window
    * Creation date: (04/01/2002 1:31:20 PM)
    * @author: Yaffin
    public class CjtApp extends JFrame {
    private JTabbedPane tabbedPane;
    private ConnectToDB cdb;
    private Connection dbconn;
    public CjtApp() {
    super("CJT Allocation Application");
    // Closes from title bar
    //and from menu
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    tabbedPane = new JTabbedPane(SwingConstants.TOP);
    tabbedPane.setForeground(Color.white);
    //add menubar to frame
    buildMenu();
    //populate and add the tabbed pane
    populateTabbedPane(dbconn);
    //tabbedPane.setEnabledAt(1, false);
    //tabbedPane.setEnabledAt(2, false);
    getContentPane().add(tabbedPane);
    pack();
    * Build menu bar and menus
    * Creation date: (04/01/2002 2:42:54 PM)
    private void buildMenu() {
    // Instantiates JMenuBar, JMenu,
    // and JMenuItem.
    JMenuBar menubar = new JMenuBar();
    JMenu menu = new JMenu("File");
    JMenuItem item1 = new JMenuItem("Connect");
    JMenuItem item2 = new JMenuItem("Exit");
    //Opens database connection screen
    item1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    //call the ConnectToDb class for a database connection
    ConnectToDB cdb = new ConnectToDB();
    dbconn = cdb.DbConnect();
    }); // Ends buildMenu method
    //Closes the application from the Exit
    //menu item.
    item2.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    }); // Ends buildMenu method
    //Adds the item to the menu object
    menu.add(item1);
    menu.add(item2);
    //Adds the menu object with item
    //onto the menu bar     
    menubar.add(menu);
    //Sets the menu bar in the frame
    setJMenuBar(menubar);
    } //closes buildMenu
    public static void main(String[] args) {
    CjtApp mainWindow = new CjtApp();
    mainWindow.setSize(640, 480);
    mainWindow.setBackground(Color.white);
    mainWindow.setVisible(true);
    mainWindow.setLocation(25, 25);
    * Add tabs to the tabbedPane.
    * Creation date: (04/01/2002 2:52:19 PM)
    private void populateTabbedPane(Connection dbconn) {
         Connection dbc = dbconn;
         tabbedPane.addTab(
         "Welcome",
    null,
    new WelcomePane(),
    "Welcome to CJT Allocation Application");
         tabbedPane.addTab(
         "Processing",
    null,
    new ProcessPane(dbc),
    "Click here to process an allocation");
         tabbedPane.addTab(
         "Reporting",
    null,
    new ReportPane(),
    "Click here for reports");
    //End
    Thanks for any assistance you can provide.
    Yaffin

    Thanks gmaurice1. I appreciate the response. I believe I understand your explanation. I am clear that the calling code needs access to the WelcomPane() object. I am assuming that the constructor for the calling class must have the JPanel WelcomePane() instance passed to it as an argument. This way I can refer directly to this specific instance of the object. Is this correct?
    Also, where would you create the set method? I tried to create a set method as part of the WelcomePane() class, and then call it from the calling class, but it didn't seem to work. Lastly, a globally accessible object? Can you explain this concept briefly? Thanks again for your help.
    yaffin

  • Commenting a Line in ABAP Editor when using SAP GUI for java

    Hi,
    In ABAP editor we can highlight the line which are to be comment and use cmd+< sign to comment those lines. What will be the command to be used to achieve the same functionality when using SAP GUI for JAVA on an iMac.

    Hello Kedar,
    please check with SAP GUI for Java 7.20 rev 5 before submitting a bug report.
    Also please verify, that cmd-< and cmd-> are not assigned as "Keyboard Shortcuts" in the "Keyboard" control panel of "System Preferences".
    Bug reports can be submitted with the [SAP Message Wizard|http://service.sap.com/message], for SAP GUI for Java please use component BC-FES-JAV.
    Best regards
    Rolf-Martin

  • How to append msg from second thread to main GUI thread?

    I am facing a problem which I cannot seem to solve.
    It involves Swing and threads. I have a main GUI running on swing. And it retrieves database information and displays it. On the same GUI I have a JTextArea box which I need another thread to update as and when that second thread recieves message via a multicast socket.
    I managed to create a runnable class of the second thread and successfully ran the second thread with the main thread in tandem. However when I use
    display.append(msgreceived);
    I get a nullPointerException. It works fine when i use System.out.println(msgreceived);.
    What should I have done instead?

    Here are part of the codes for my admin module.
    public class Admin extends JFrame implements ActionListener {
    //declares all the global variables
    private JTextArea display;
    public Admin() {
    super("BX Online - Admin Module");
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    AdminGUI();
    AdminGUI() {
    contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    JPanel newsbox = new JPanel();
    display = new JTextArea(2, 40);
    display.setEditable(false);
    newsbox.add(display);
    contentPane.add(newsbox);
    contentPane.add(tabpaneO);
    setBounds(70, 50, 300, 500);
    pack();
    setVisible(true);
    // all the methods activated by buttons goes here
    static public void main(String[] argv) {
    Admin a = new Admin();
    News b = new News("test");
    The following are part of the codes for my runnable class.
    public class News implements Runnable {
    protected boolean again = true;
    private String name, recieve; //the global variables
    private Thread t;
    public JTextArea display;
    public BXnews(String threadname) {
    name = threadname;
    t = new Thread(this, name);
    System.out.println("New Thread: " + t); //visual check to make sure thread is started.
    t.start();
    private void msg() {
    String recieve = ("testing");
    System.out.println(recieve);
    display.append(recieve);
    public void run() {
    while (again) //creates a loop so thread does not close
    {msg();}
    Well thats abt it. I'm not sure if you can compile this but basically the part I left out was the setup link for the News class which I don't see the need to add as what I primarily intend is for the message testing in News class to appear in Admin class thread in JTextArea "display".

  • A certain swing component...

    Can anyone tell me how to setup a JTextArea component to have the ability to scroll? Also, Is there some way that you can limit the amount of lines that will remain in memory of the JTextArea so that it will conserve memory? Thanks to the Java community for any help.

    Here's the sampler code that creates a text area for your 1st question:
    JTextArea textArea = new JTextArea(
    "This is an editable JTextArea " +
    "that has been initialized with the setText method. " +
    "A text area is a \"plain\" text component, " +
    "which means that although it can display text " +
    "in any font, all of the text is in the same font."
    textArea.setFont(new Font("Serif", Font.ITALIC, 16));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    To provide scrolling capability, you should put the text area in a scroll pane as below:
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    areaScrollPane.setBorder(...create border...);
    A text area is typically managed by a scroll pane. If you put a text area in a scroll pane, be sure to set the scroll pane's preferred size or use a text area constructor that sets the number of rows and columns for the text area.
    Good luck.

  • Maximum size of a JTextArea

    Hi,
    I've got a JTextArea component which contains the content of a file. This file can be very large (>10Mo).
    I fall in memory exception with a file size of 10 Mo but my program runs correctly with a file size < 5 Mo.
    Is there a solution for the treatment of very large files.
    Thanks for your help.

    I'd suggest using a random access file so you can avoid loading the entire file into memory at once.
    If you create the java.io.File on your file, you can get the length of the file in bytes. Then instead of loading and presenting the entire file at once in the JEditorPane present only a small chunk of the file and a couple of "Next Page", "Previous Page" buttons (or whatever). Using the RandomAccessFile means you can load only a specific portion of the file when required.
    Take a look at:
    java.io.PxRandomAccessFile

  • Copy and Paste into JTextArea

    Hi,
    I have a problem with the JTextArea component. When I try to copy and paste text (from like notepad or web browser) into the JTextArea it works fine. But on other computers it won't respond to the "ctrl-v" command. I'm having trouble on figuring this out. Any suggestions?

    Are the "other computers" running Windows?

Maybe you are looking for