Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: JScrollPane cant paint correctly when scroll

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JScrollPane cant paint correctly when scroll

    Hi,

    Anyone know what is the problem? how to make it paint correctly when scroll?



    import javax.swing.*;
    import java.awt.*;
     
    public class MainClass extends JFrame{
    	public static void main(String[] args){
    		MainClass aa = new MainClass();
    		aa.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    		bb b = new bb();
    		b.setPreferredSize(new Dimension(1000, 1000));
    		JScrollPane sp = new JScrollPane(b);
     
    		aa.getContentPane().add(sp);
    		aa.setSize(100,100);
    		aa.setVisible(true);
    		aa.repaint();
    	}
    }
    class bb extends JPanel{
    	public void paint(Graphics g){
    	//	g.drawString("hihihihi",20,20);
    	}
    }

    [Edited]
    It is solved, i just nid to repaint the jframe everytime i adjust the scrollbar. case closed. thanks.
    Last edited by fuweng; June 8th, 2011 at 02:30 AM.


  2. #2
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JScrollPane cant paint correctly when scroll

    ignore the "aa.repaint()", i forgot to remove it.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JScrollPane cant paint correctly when scroll

    it is resolved now. thanks.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: JScrollPane cant paint correctly when scroll

    Welcome to the forums fuweng.

    Well done for solving this youself. I have marked the thread as Solved.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JScrollPane cant paint correctly when scroll

    I am facing the same problem. Can fuweng or someone else tell me how exactly to resolve the issue. How do I repaint the JFrame when the scrollbar is adjusted?

Similar Threads

  1. JAVA netbeans - GUI how to get my scroll bar to work?!
    By camel in forum AWT / Java Swing
    Replies: 5
    Last Post: April 18th, 2011, 08:15 AM
  2. 1 vertical scroll bar fro 2 jtextareas
    By fortune2k in forum AWT / Java Swing
    Replies: 8
    Last Post: March 4th, 2011, 02:04 PM
  3. Replies: 3
    Last Post: November 9th, 2010, 01:19 PM
  4. [SOLVED] Scroll down in JOptionPane and window problems.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 60
    Last Post: June 16th, 2010, 01:04 PM
  5. Replies: 1
    Last Post: May 21st, 2009, 04:41 AM