Results 1 to 8 of 8
  1. #1
    Tastosis is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default JScrollbar not working

    Whenever I type something that exceeds the size of the JTextArea, the Scrollbar won't appear :confused:
    I already used the JScrollPane

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class converter {
    
    public static void main(String[] args) {
            JFrame win = new Gui2();
       }
    }
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Gui2 extends JFrame {
    
        private JButton button;
        private JTextArea area;
        private JTextArea area2;
        private JScrollPane scroll;
        private JScrollPane scroll2;
        private JSplitPane splitPane;
        private JPanel forbutton;
        private JPanel content;
    
        public Gui2() {
            initComponents();
        }
    
        private void initComponents() {
    
            button = new JButton("CONVERT");
    
            forbutton = new JPanel();
            forbutton.add(button);
    
            area = new JTextArea(40, 45);
            area2 = new JTextArea(40, 45);
    
            scroll = new JScrollPane(area);
            add(scroll);
    
            scroll2 = new JScrollPane(area2);
            add(scroll2);
    
            splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, area, area2);
            splitPane.setOneTouchExpandable(false);
            splitPane.setResizeWeight(0.5);
    
            content = new JPanel();
            content.setLayout(new BorderLayout());
            content.add(splitPane, BorderLayout.CENTER);
            content.add(forbutton, BorderLayout.PAGE_END);
    
            setContentPane(content);
            setTitle("LTS Converter");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            pack();
    
            HandlerClass handler = new HandlerClass();
            button.addActionListener(handler);
        }
    
        private class HandlerClass implements ActionListener {
    
            public void actionPerformed(ActionEvent event) {
            	String one = "println";
            	String two = "import";
            	String three = "int";
            	String four = "float";
            	String five = "double";
            	String six = "static";
            	String seven = "char";
            	String eight = "String";
            	String nine = "main";
            	String ten = "class";
            	String _11 = "for";
            	String _12 = "do";
            	String _13 = "while";
            	String _14 = "public";
            	String _15 = "void";
    
            	String a = "imprimareln";
            	String b = "importare";
            	String c = "intreg";
            	String d = "pluti";
            	String e = "dublu";
            	String f = "statica";
            	String g = "caracter";
            	String h = "serie";
            	String i = "uscat";
            	String j = "clasa";
            	String k = "pentru";
            	String l = "nu";
            	String m = "rastimp";
            	String n = "publice";
            	String o = "gol";
    
            	String code = area.getText();
    
            	String code2 = code.replace(one, a);
            	String code3 = code2.replace(two, b);
            	String code4 = code3.replace(three, c);
            	String code5 = code4.replace(four, d);
            	String code6 = code5.replace(five, e);
            	String code7 = code6.replace(six, f);
            	String code8 = code7.replace(seven, g);
            	String code9 = code8.replace(eight, h);
            	String code10 = code9.replace(nine, i);
            	String code11 = code10.replace(ten, j);
            	String code12 = code11.replace(_11, k);
            	String code13 = code12.replace(_12, l);
            	String code14 = code13.replace(_13, m);
            	String code15 = code14.replace(_14, n);
            	String code_final = code15.replace(_15, o);
    
            	area2.setText(code_final);
            }
    	}
    }

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

    Default

    You're adding area and area2 to the JScrollPanes, but then you add area and area2 directly into the JSplitPane, completely ignoring the JScrollPanes. It shouldn't surprise you that you're having this behavior.

  3. #3
    Tastosis is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    omg I don't know what's wrong. I just reformatted my computer, I re-installed JCreator. I did the necessary stuff like adding the path, etc.. I have a problem:

    Last edited by Tastosis; 03-21-2011 at 02:34 PM.

  4. #4
    Tastosis is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    Here's what happens when I compile the Gui2 class:

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

  6. #6
    Tastosis is offline Member
    Join Date
    Mar 2011
    Posts
    15
    Rep Power
    0

    Default

    Thanks.

    But if you look at my previous posts, I have a new problem

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

    Default

    Then start a new thread.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

Similar Threads

  1. paint with JScrollBar
    By shakeel in forum Java 2D
    Replies: 5
    Last Post: 12-23-2010, 05:35 PM
  2. Problem with JScrollBar
    By Arthur in forum AWT / Swing
    Replies: 3
    Last Post: 02-19-2010, 03:59 AM
  3. A problem with JScrollBar and the Jbutton
    By cowboy in forum New To Java
    Replies: 5
    Last Post: 12-19-2009, 10:17 PM
  4. JScrollBar
    By solomon_13000 in forum AWT / Swing
    Replies: 1
    Last Post: 07-01-2009, 08:46 AM
  5. problem with jscrollbar in my applet
    By leonard in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 12:39 AM

Posting Permissions

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