Results 1 to 6 of 6
  1. #1
    Jyzef is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default JScrollPane + Image

    Hello, I don't know where is error??
    Java Code:
     JPanel panel = new
                      JPanel()
              {
                  public void paintComponent(Graphics g)
                  {
                      if (image != null)
                          g.drawImage(image, 0, 0, null);
    
                  }
    
              };
    
              JScrollPane imageScrollPanel = new JScrollPane();
       
                    imageScrollPanel.getViewport().add(panel);
                    panel.setPreferredSize(new Dimension(250,250));
    
                    frame.add( imageScrollPanel, BorderLayout.CENTER );
    
             
    
            frame.add(panel);
    Last edited by Jyzef; 06-01-2010 at 11:24 PM.

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    Can you provide the error?

  3. #3
    Jyzef is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    the image is shown but the scroll bars are not visible and the scroll view does not work. Any suggestions on that?

  4. #4
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    Have you tried constructing a ImageIcon from the Image, adding it to a JLabel and adding that to the JPanel?

  5. #5
    Jyzef is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    I can't do it, because after I must edit Image (for example filter)

  6. #6
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    Quote Originally Posted by Jyzef View Post
    Java Code:
        JScrollPane imageScrollPanel = new JScrollPane();
       
        imageScrollPanel.getViewport().add(panel);
    
        frame.add( imageScrollPanel, BorderLayout.CENTER );
    
        frame.add(panel);
    You seem to be adding the panel to both the frame and the scrollpanel.

    Also, as far as i understand you should be using
    Java Code:
    JScrollPane imageScrollPanel = new JScrollPane(panel);
    instead of making a scroll panel and then adding the panel to it.

    Berkeleybross

Similar Threads

  1. JScrollPane problem
    By KArelVH in forum AWT / Swing
    Replies: 6
    Last Post: 04-27-2009, 10:40 PM
  2. jscrollpane
    By kaemonsaionji in forum New To Java
    Replies: 3
    Last Post: 02-25-2009, 09:39 AM
  3. problem with Jscrollpane
    By ravrajesh.ap in forum AWT / Swing
    Replies: 5
    Last Post: 01-03-2009, 11:38 PM
  4. help with JScrollPane
    By tommy in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:58 PM
  5. how to draw an image inside of jscrollpane
    By paty in forum Java Applets
    Replies: 1
    Last Post: 07-24-2007, 01:44 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
  •