Results 1 to 3 of 3
  1. #1
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default JScrollPane questions

    I get no errors with this code, but no matter how I try to add this JScrollPane, it doesn't let me scroll down the text document. So I'm using this method to make "cards" for a CardLayout in a JFrame. If I change the end of the method to
    Java Code:
     intro.add(scroll);
    I just get an empty box with no scrollbars. The way it is shown here things appear just as when I do not try to add the JScrollPane. Probably an obvious error, but I'm missing it. Anyone help?
    Java Code:
    static JPanel makeCardIntro(){
    		URL file = AlphaPattern.class.getResource("Intro.rtf");
    		JPanel intro = new JPanel();
    		intro.setBackground(Color.WHITE);
    		
    		JEditorPane introHTM = new JEditorPane();
    		JScrollPane scroll = new JScrollPane();
    		scroll.setPreferredSize(new Dimension(820, 820));
    		scroll.add(introHTM);
    		introHTM.setPreferredSize(new Dimension(800, 800));
    		introHTM.setMaximumSize(new Dimension(1100, 800));
    		introHTM.setMinimumSize(new Dimension(800, 800));
    		introHTM.setEditable(false);
    		
    		try {
    			introHTM.setPage(file);
    			
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		intro.add(introHTM);
    		return intro;
    	}

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: JScrollPane questions

    Sorry I'm about to run off into the weekend. Su just a quick link to the how to.
    How to Use Scroll Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    NotTooOld is offline Hostage
    Join Date
    Apr 2013
    Location
    China
    Posts
    128
    Rep Power
    0

    Default Re: JScrollPane questions

    Quote Originally Posted by PhHein View Post
    Sorry I'm about to run off into the weekend. Su just a quick link to the how to.
    How to Use Scroll Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    Maybe the break from looking at it while I wrote my question helped. Or adding the line setting the policy? Anyway, working now. YAY!
    Java Code:
    	static JPanel makeCardIntro(){
    		URL file = AlphaPattern.class.getResource("Intro.rtf");
    		JPanel intro = new JPanel();
    		intro.setBackground(Color.WHITE);
    		
    		JEditorPane introHTM = new JEditorPane();
    		JScrollPane scroll = new JScrollPane(introHTM);
    		scroll.setVerticalScrollBarPolicy(
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    		scroll.setPreferredSize(new Dimension(820, 820));
    		introHTM.setPreferredSize(new Dimension(800, 800));
    		introHTM.setMaximumSize(new Dimension(1100, 800));
    		introHTM.setMinimumSize(new Dimension(800, 800));
    		introHTM.setEditable(false);
    		
    		try {
    			introHTM.setPage(file);
    			
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		intro.add(scroll);
    		return intro;
    	}

Similar Threads

  1. JScrollPane - A little help please
    By Ermm in forum New To Java
    Replies: 7
    Last Post: 01-23-2012, 06:26 AM
  2. JScrollPane
    By mitra in forum AWT / Swing
    Replies: 2
    Last Post: 11-15-2011, 03:20 PM
  3. JScrollPane Help
    By Huskies in forum AWT / Swing
    Replies: 2
    Last Post: 08-06-2011, 06:06 PM
  4. Help with jScrollPane
    By weikang in forum SWT / JFace
    Replies: 1
    Last Post: 02-04-2011, 03:30 AM
  5. JScrollPane
    By UJJAL DHAR in forum New To Java
    Replies: 12
    Last Post: 08-17-2010, 06:47 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
  •