Results 1 to 3 of 3
  1. #1
    rgrant222's Avatar
    rgrant222 is offline Member
    Join Date
    Jul 2010
    Location
    Lawrenceville, Ga
    Posts
    17
    Rep Power
    0

    Default ScrollPane Scrollbar's Not Working in Applet

    So over the past few months, I've been writing console applications to learn Java. I'm trying to learn about AWT before moving on to Swing. Everything was going well, but I can't figure out why the scrollbars in my ScrollPane aren't working.

    Here's the code for ScrollingImage.java:
    Java Code:
    import java.awt.*;
    import java.applet.Applet;
    
    class ImageCanvas extends Component {
    	private Image image;
    
    	public ImageCanvas(Image image) {
    		this.image = image;
    	}
    
    	public void paint(Graphics g) {
    		if (image != null) {
    			g.drawImage(image, 0, 0, this);
    		}
    	}
    }
    
    public class ScrollingImage extends Applet {
    	public void init() {
    		setLayout(new BorderLayout());
    
    		ScrollPane sp = 
    			new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
    		Image img = 
    			this.getImage(this.getCodeBase(), "./images/moon1.gif");
    
    		sp.add(new ImageCanvas(img));
    		this.add(sp, BorderLayout.CENTER);
    	}
    }
    ...and here's the code for appletViewer.html:
    Java Code:
    <html>
    	<head>
    		<title>Scrolling Image</title>
    	</head>
    	<body bgcolor=#eee>
    		<applet code=ScrollingImage.class height=500 width=500></applet>
    	</body>
    </html>
    The GIF is displayed properly, but the scrollbars are grayed out! I think it might have something to do with the layout, but that's only because it's the part I know the least about and everything else seems correct. Any suggestions?
    Learn something new... wiser-today.blogspot.com

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    I'm trying to learn about AWT before moving on to Swing
    Bad idea. You will need to unlearn many things in order to use Swing properly. For example displaying images and using scrollpanes is completely different in Swing so all the code you just wrote will need to be rewritten. I suggest you learn Swing first. Start with Trail: Creating a GUI With JFC/Swing: Table of Contents (The Java™ Tutorials)

  3. #3
    rgrant222's Avatar
    rgrant222 is offline Member
    Join Date
    Jul 2010
    Location
    Lawrenceville, Ga
    Posts
    17
    Rep Power
    0

    Default

    Right on. So would you recommend learning Swing before learning AWT, or simply forsaking AWT?

    I've heard that future support for Swing is not planned... does anyone know if that's true? If so, what is planned?
    Learn something new... wiser-today.blogspot.com

Similar Threads

  1. Applet not working in browser
    By gkr1989 in forum Java Applets
    Replies: 3
    Last Post: 07-03-2009, 09:43 AM
  2. Applet not working
    By jyothi.priyanka in forum New To Java
    Replies: 5
    Last Post: 04-16-2009, 08:18 AM
  3. Shape drawing applet not working...
    By evapisces in forum Java Applets
    Replies: 0
    Last Post: 11-17-2008, 11:46 PM
  4. Tree with Listener not working when added to ScrollPane
    By praveen.kb in forum AWT / Swing
    Replies: 2
    Last Post: 01-09-2008, 07:06 AM
  5. Applet button not working
    By letmeoutofhere in forum Java Applets
    Replies: 9
    Last Post: 11-14-2007, 12:15 PM

Tags for this Thread

Posting Permissions

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