Viewing Image format files in JPedal’s Customizable Viewer
JPedal includes a very comprehensive viewer which can view a wide range of image file formats as well as PDF files. The Viewer is customizable allowing its appearance to be altered to best suit your needs. The Viewer is written in Java but can be run from other languages or command line.
If you do not have JPedal, you can download a trial copy:
View Image files from Command Line or another language
java -jar jpedal.jar --view "image.png"
View Image files in a new window with Java
Viewer viewer = new Viewer();
viewer.setupViewer();
viewer.executeCommand(ViewerCommands.OPENFILE, "image.png");
This uses the JPedal Viewer class. The Viewer defaults to using the Look and Feel of the operating system, if you want to change this fully details can be found here.
Adding the Viewer to a Swing Component
//Create display JFrame
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new BorderLayout());
//This could be any JPanel from your application
final JPanel rootContainer = frame.getContentPane();
Viewer viewer = new Viewer(rootContainer, null);
viewer.setupViewer();
viewer.executeCommand(ViewerCommands.OPENFILE, "image.png");
//add viewer to your application
frame.add(rootContainer, BorderLayout.CENTER);
//Display the example frame with embedded Image viewer
frame.setTitle("Viewer in External Frame");
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
As well as adding the Viewer to your own application you can also customize the Viewer to control which options are present using the Viewers properties file. Once you have created a properties file that displays the options you require it can be loaded by the Viewers constructor shown above. To do this you just need to pass in the file’s path as the second parameter.