Results 1 to 3 of 3
  1. #1
    tjw09003 is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

    Default Why won't the scrollbar show up in a JTextArea?

    I'm not sure what I'm doing wrong

    Java Code:
    package com.tjffx.jNotes;
    
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.UIManager;
    import javax.swing.UnsupportedLookAndFeelException;
    
    
    
    public class TextEditor extends JFrame {
        
        /**
         *    jNotes Android Sync
         */
        private static final long serialVersionUID = 1L;
        private Toolkit toolkit;
        public JTextField txt_test = new JTextField();
        public JTextArea txt_editor = new JTextArea(10,20);
        JScrollPane scrollingpane = new JScrollPane(txt_editor,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        
        
        public static void setNativeLnF(){
            //SET NATIVE LnF
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (UnsupportedLookAndFeelException e) {
                e.printStackTrace();
            }
        }
        
        public static void main(String[] args){
           setNativeLnF();
    
            TextEditor win = new TextEditor();
            win.setVisible(true);        
        }
        
        public TextEditor(){
            //SETUP WINDOW
            setTitle("jNotes");
            setSize(300, 200);
            toolkit = getToolkit();
            Dimension size = toolkit.getScreenSize();
            setLocation((size.width - getWidth())/2, (size.height - getHeight())/2);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            
            //SETUP PANEL
            JPanel panel = new JPanel();
            getContentPane().add(panel);
            panel.setLayout(null);
            
            //SETUP BUTTONS
            JButton beep = new JButton("Sync");
            beep.setBounds(0, 0, 80, 20);
            beep.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    testFunction();
                }
            });
            
            //SETUP TEXTAREA
            txt_editor.setBounds(0,20,200,300);
    
            
            //ADD TO PANEL
            panel.add(beep);
            panel.add(txt_editor);
            panel.add(scrollingpane);
           
        }
        
        void testFunction(){
            
        }
        
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You're adding the text component to both the JScrollPane and the JPanel, and so it will only display in one or the other, not both. You should add it to the JScrollPane and then add just the JScrollPane and not the text component to the main JPanel. Also, don't setBounds on the JTextArea but rather set the preferred size. In fact, you should set bounds on nothing here but instead learn to use the user-friendly layout managers.

  3. #3
    tjw09003 is offline Member
    Join Date
    Aug 2010
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 05-27-2010, 10:54 AM
  2. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 07:51 PM
  3. How can I show my log class in jTextArea
    By mtz1406 in forum AWT / Swing
    Replies: 4
    Last Post: 10-29-2009, 12:15 PM
  4. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 AM
  5. How to always show the last line in my JTextArea?
    By Ashley in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 01:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •