Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:03:17+00:00 2026-05-25T20:03:17+00:00

I have a simple app where I want to show a large image in

  • 0

I have a simple app where I want to show a large image in a scrollable panel. I’m using NavigableImagePanel from http://today.java.net/pub/a/today/2007/03/27/navigable-image-panel.html

Firstly the result I’m getting – Rotate and Resize

The image is currently a very small panel near the top buttons. This is with BorderLayout.CENTER

The code for NavigableImagePanel:

http://pastebin.com/1wHRwMJU

and my OpenImage.java code:

import java.awt.*;
import java.awt.event.*;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;


public class OpenImage extends JFrame implements ActionListener{
/**
 * 
 */
private static final long serialVersionUID = 9066218264791891436L;
Image img;

public OpenImage() throws IOException{
    super("Resize and Rotate");

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    BorderLayout grid = new BorderLayout(); 

    //this.setLayout(grid);
    setSize(900,700);
    setVisible(true);   


    //Row 1 holds some important buttons 
    //FlowLayout layout1 = new FlowLayout();
    //MigLayout mig = new MigLayout();
    JPanel row1 = new JPanel();
    //LayoutManager grid = new BoxLayout(row1, BoxLayout.X_AXIS);
    //row1.setLayout(grid);
    //row1.setLayout(BorderLayout.NORTH);
    //row1.setMaximumSize(new Dimension(100,100));
    BorderLayout border = new BorderLayout();
    //row1.setPreferredSize(new Dimension(0, 400));

    JButton open = new JButton ("Open");
    open.addActionListener(this);
    JButton rotate = new JButton("Rotate");
    rotate.addActionListener(this);
    JButton resize = new JButton("Resize");
    resize.addActionListener(this);
    JButton exit = new JButton ("Exit"); 
    exit.addActionListener(this);
    row1.add(open);
    row1.add(rotate);
    row1.add(resize);
    row1.add(exit);




    //This section has a workable picture panel, but it is too large. 
    //ImagePanel imagepanel = new ImagePanel();
    BorderLayout grid1 = new BorderLayout();
    Container cp = getContentPane();
    cp.setLayout(grid1);

    //add(row1);

    //JScrollPane row2 = new JScrollPane(imagepanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);


    BufferedImage img = ImageIO.read(new File("/home/adam/snow.jpg"));

    NavigableImagePanel imagepanel = new NavigableImagePanel(img);

    JPanel row2 = new JPanel();
    row2.add(imagepanel);
    //row2.repaint();
    JButton save = new JButton("Save");
    JPanel row3 = new JPanel();
    row3.add(save);

    cp.add(BorderLayout.NORTH, row1);
    cp.add(BorderLayout.CENTER, row2);
    cp.add(BorderLayout.SOUTH, row3);


}




public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command == "Exit"){
        System.exit(0);
    }
    if (command == "Open"){
        JFileChooser chooser = new JFileChooser();
        int returnVal = chooser.showOpenDialog(this);


    }
}



//This method below is now being deprecat


public static void main(String [] args){
    try {
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (UnsupportedLookAndFeelException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    }
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    try {
        JFrame frame = new OpenImage();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:03:18+00:00Added an answer on May 25, 2026 at 8:03 pm
    1. Code that you post here missed there lots of Java imports, can’t see here any Java imports from Swing packages, and import for Image.
    2. setVisible(true); must be last code line in the constructor.
    3. In all case setBackground() can help you to find any problem.
    4. In all case to try use pack() instead of setSize(900,700);
    5. Since I set imagepanel.setPreferredSize(new Dimension(600, 400));, that’s wrong JComponents to have to returns preferred size, then pack() will work correctly.
    6. No idea from where you get this code, so hardly could be works without exceptions.
    7. just cleanup useless mess

    enter image description here

    from code

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    import javax.swing.border.LineBorder;
    
    public class OpenImage extends JFrame implements ActionListener {
    
        private static final long serialVersionUID = 9066218264791891436L;
        private Image img;
    
        public OpenImage() {
            super("Resize and Rotate");
    
            JButton open = new JButton("Open");
            open.addActionListener(this);
            JButton rotate = new JButton("Rotate");
            rotate.addActionListener(this);
            JButton resize = new JButton("Resize");
            resize.addActionListener(this);
            JButton exit = new JButton("Exit");
            exit.addActionListener(this);
    
            JPanel row1 = new JPanel();
            row1.setBackground(Color.red);
            row1.setLayout(new FlowLayout());
            row1.setBorder(new LineBorder(Color.black, 1));
            row1.add(open);
            row1.add(rotate);
            row1.add(resize);
            row1.add(exit);
    
            JPanel imagepanel = new JPanel();
            imagepanel.setLayout(new BorderLayout());
            imagepanel.setBackground(Color.blue);
            imagepanel.setBorder(new LineBorder(Color.black, 1));
            imagepanel.setPreferredSize(new Dimension(600, 400));
    
            JPanel row2 = new JPanel();
            row2.setLayout(new BorderLayout(10, 10));
            row2.setBorder(new LineBorder(Color.black, 1));
            row2.add(imagepanel, BorderLayout.CENTER);
            row2.setBackground(Color.red);
            JButton save = new JButton("Save");
    
            JPanel row3 = new JPanel();
            row3.setBorder(new LineBorder(Color.black, 1));
            row3.setBackground(Color.green);
            row3.setLayout(new FlowLayout());
            row3.add(save);
    
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setLayout(new BorderLayout(10, 10));
            add(BorderLayout.NORTH, row1);
            add(BorderLayout.CENTER, row2);
            add(BorderLayout.SOUTH, row3);
            pack();
            setVisible(true);
        }
    
        public void actionPerformed(ActionEvent e) {
            String command = e.getActionCommand();
            if (command == "Exit") {
                System.exit(0);
            }
            if (command == "Open") {
                JFileChooser chooser = new JFileChooser();
                int returnVal = chooser.showOpenDialog(this);
            }
        }
    
        public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    OpenImage openImage = new OpenImage();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple Rails app. Basically an article with comments. I want
I'm working on a relatively simple Android app. I want it to have an
I have one simple app that suppose to get information from user and send
I have a simple webapp in Django for an iPhone app. I want to
I'm wondering about this: I have a simple facebook-connect app that will only show
I got an interesting request from the higher ups. They want a simple app
I'm writing simple WP7 app to study ReactiveUI. I want to show a collection
This is a real newbie question. I have simple app that selects a picture
I have simple Sinatra app. web.rb: require 'sinatra' get '/' do Hello end Gemfile:*
I have a simple app where you can login it looks like this: {{#view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.