Image Selection

Image Selection

View Answers

May 27, 2008 at 3:23 PM

Hi friend,

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;

public class DisplayImage extends JFrame {
JLabel promptLabel;
JTextField prompt;
JButton button;
JFileChooser fileChooser;
JComboBox comboBox;
JButton saveButton;
public DisplayImage() {
super("Image Selection program");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container con = getContentPane();
JPanel inputPanel = new JPanel();
promptLabel = new JLabel("Filename:");
inputPanel.add(promptLabel);
prompt = new JTextField(20);
inputPanel.add(prompt);
button = new JButton("Browse");
inputPanel.add(button);
con.add(inputPanel, BorderLayout.NORTH);

fileChooser = new JFileChooser();
button.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
if (selectedFile != null) {
prompt.setText(selectedFile.getAbsolutePath());
}
}
}
}
);

JPanel outputPanel = new JPanel();
String writerFormats[] = ImageIO.getWriterFormatNames();
ComboBoxModel comboBoxModel = new DefaultComboBoxModel(writerFormats);
comboBox = new JComboBox(comboBoxModel);
outputPanel.add(comboBox);
saveButton = new JButton("Save");
outputPanel.add(saveButton);
saveButton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String name = prompt.getText();
File file = new File(name);
if(file.exists()) {
BufferedImage image = ImageIO.read(file.toURL());
if(image == null) {
System.err.println("Invalid input file format");
} else {
String selection = (String)comboBox.getSelectedItem();
String outputFilename = name + "." + selection;
File outputFile = new File(outputFilename);
boolean found = ImageIO.write(image,selection, outputFile);
if (found) {
JDialog window = new JDialog();
Container windowContent = window.getContentPane();
BufferedImage newImage = ImageIO.read(outputFile);
JLabel label = new JLabel(new ImageIcon(newImage));
JScrollPane pane = new JScrollPane(label);
windowContent.add(pane,BorderLayout.CENTER);
window.setSize(500, 500);
window.show();
} else {
System.err.println("Error saving");
}
}
} else {
System.err.println("file name not select!");
}
} catch (MalformedURLException mur) {
System.err.println("Select file name not found");
} catch (IOException ioe) {
System.err.println("Error reading file");
}
}
}
);

con.add(outputPanel, BorderLayout.SOUTH);

}
public static void main(String args[]){
System.out.println("Display image on new window after selecting!");
JFrame frame = new DisplayImage();
frame.setSize(500,300);
frame.show();
}
}
------------------------------------------------
Read for more informaton.

http://www.roseindia.net/java/









Related Tutorials/Questions & Answers:
image selection
image selection  hi my issue is : I have select dropdown list when I selected image it displays some default color having image I change the color... it redirect to error image page. can you tell how to solve this problem and where
Image Selection - Swing AWT
Image Selection  Hi, I need to provide the image selection facility...; JButton saveButton; public DisplayImage() { super("Image Selection program... click on any item, the image of that item should be selected as done in windows
Advertisements
Syntax for image selection Urgent - JSP-Servlet
Syntax for image selection Urgent  Respected Sir/Madam, I am using the following syntax to know whether radio button has been clicked or not: for(var i=0;i  Hi friend, now show the question no 2129 Here
Image Selection Reply Urgent.. - JSP-Servlet
Image Selection Reply Urgent..  Respected Sir/Madam, I am R.Ragavendran.. Thanks for yuor fast response.. Sir actually I will be much more convenient if you provide me with coding.. I dont know to work with images as i
Very urgent Image Selection - JSP-Servlet
Very urgent Image Selection  Respected Sir/Madam, I am R.Ragavendran.. If you are telling that your coding works fine, then can u plz tell me or send me the output of the following code asap? var imageURL
Image selection instead of radio button very urgent.. - JSP-Servlet
Image selection instead of radio button very urgent..  Respected Sir/Madam, I am R.Ragavendran.. Actually in the following using radio... successfully. But I need some icon or some pictorial selection instead
highlight uitableviewcell on selection
the UITableViewCell on selection in my application.   UITableViewCell... highlight it or use the default selection for the cell in UITableView. Also you can disable the the stye by setting StyleNone to cell selection. But in case
Selection based on other selection in jsp
Selection based on other selection in jsp  I am trying to create a jsp page. Where I am having a select list containing category name and for each... selection on same jsp page such that when someone select a category only the products
image
image  how to add the image in servlet code
changing selection color of <button>
changing selection color of   dear all, i have loaded image in border less button tag when button is selected with tab key i get brown color rectangle around image. how do i change color of that rectangle from brown to white
insert multiple selection - Java
insert multiple selection - Java  how to insert multiple selection values from html into database using servlets
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
ModuleNotFoundError: No module named 'selection'
ModuleNotFoundError: No module named 'selection'  Hi, My Python... 'selection' How to remove the ModuleNotFoundError: No module named 'selection' error? Thanks   Hi, In your python environment you
image
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
Help With Costructing Selection sort?
Help With Costructing Selection sort?  Using a selection sort, for each entry in the array, display the original index of the first dimension... in advance!   Please visit the following link: Java Selection Sort
interrelated two selection box
interrelated two selection box  hi i need two selection box .in 1 box all designation like manager, ceo etc , onclick on manager i should get list of managers names in second selection box.. like wise so on. from database
Selection Using JoptionPane
Selection Using JoptionPane  Help, can someone provide me the code using JOptionPane for the following:- Part A 1) Prompt user to make 3 selection... Modify the above application so that if user makes a selection that the user has
checkbox selection in jsp
checkbox selection in jsp  hey guys i am working on a web based project using jsp. In my project i am having 9 check boxes in 3 rows in the same form. I want to select i check box from each row and also i want to avoid many
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'model-selection'
ModuleNotFoundError: No module named 'model-selection'  Hi, My... named 'model-selection' How to remove the ModuleNotFoundError: No module named 'model-selection' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'blacken-selection'
ModuleNotFoundError: No module named 'blacken-selection'  Hi, My... named 'blacken-selection' How to remove the ModuleNotFoundError: No module named 'blacken-selection' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'causal-selection'
ModuleNotFoundError: No module named 'causal-selection'  Hi, My... named 'causal-selection' How to remove the ModuleNotFoundError: No module named 'causal-selection' error? Thanks   Hi, In your
selection box linked with textarea
selection box linked with textarea    function get_val(tot_val1) { document.getElementById('TextBox1').value = tot_val1; alert(tot_val1... detals i have in db with all fields .. like wise i have names in selection box sham
Displaying files on selection of date.
Displaying files on selection of date.  Hi, I am developing a GUI, where i select from and to date. On selection of from and to date the GUI should show the particular txt files of the selected date. I want the java logic
Selection With Ajax and JSP
Selection With Ajax and JSP  I am working at a jsp page using ajax for country , state, city selection. so if he select country it will populate the state and city selection (both). After selecting country if he select city
else if (selection = * 'M'); - Java Beginners
else if (selection = * 'M');  I am trying to get 2 numbers 2... if (selection = * 'M'); ^ this is my program - what am i...; System.out.print("Enter A(dd), S(ubtract), M(ultiply):"); selection = (char
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop.  i am using cmd prompt to run and execute the java pgm. here i need your help... but here am getting multiple selection(previous selected item also coming again
enable text box and label on selection
enable text box and label on selection  hello, Please tell me how to enable label and text box on selection of drop down list box. in drop down list box all values come from database. please reply
Selection Sort in Java
Selection sort in Java is used to sort the unsorted values in an array. In selection sorting algorithm, the minimum value in an array is swapped... position. This procedure is repeated till the array is sorted completely. Selection
ModuleNotFoundError: No module named 'colcon-package-selection'
ModuleNotFoundError: No module named 'colcon-package-selection'  Hi...: No module named 'colcon-package-selection' How to remove the ModuleNotFoundError: No module named 'colcon-package-selection' error? Thanks  
ModuleNotFoundError: No module named 'ecg-feature-selection'
ModuleNotFoundError: No module named 'ecg-feature-selection'  Hi...: No module named 'ecg-feature-selection' How to remove the ModuleNotFoundError: No module named 'ecg-feature-selection' error? Thanks   Hi
ModuleNotFoundError: No module named 'naive-feature-selection'
ModuleNotFoundError: No module named 'naive-feature-selection'  Hi...: No module named 'naive-feature-selection' How to remove the ModuleNotFoundError: No module named 'naive-feature-selection' error? Thanks   
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' ...: No module named 'odoo10-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection'
ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection' ...: No module named 'odoo11-addon-pos-lot-selection' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-pos-lot-selection' error
ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox'
ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox'  ...: No module named 'rpi-feature-selection-toolbox' How to remove the ModuleNotFoundError: No module named 'rpi-feature-selection-toolbox' error
ModuleNotFoundError: No module named 'branch-and-bound-feature-selection'
ModuleNotFoundError: No module named 'branch-and-bound-feature-selection' ...: ModuleNotFoundError: No module named 'branch-and-bound-feature-selection' How to remove the ModuleNotFoundError: No module named 'branch-and-bound-feature-selection
ModuleNotFoundError: No module named 'colcon-package-selection'
ModuleNotFoundError: No module named 'colcon-package-selection'  Hi...: No module named 'colcon-package-selection' How to remove the ModuleNotFoundError: No module named 'colcon-package-selection' error? Thanks  
ModuleNotFoundError: No module named 'ecg-feature-selection'
ModuleNotFoundError: No module named 'ecg-feature-selection'  Hi...: No module named 'ecg-feature-selection' How to remove the ModuleNotFoundError: No module named 'ecg-feature-selection' error? Thanks   Hi
ModuleNotFoundError: No module named 'feature-selection-fdr'
ModuleNotFoundError: No module named 'feature-selection-fdr'  Hi...: No module named 'feature-selection-fdr' How to remove the ModuleNotFoundError: No module named 'feature-selection-fdr' error? Thanks   Hi
ModuleNotFoundError: No module named 'knock-feature-selection'
ModuleNotFoundError: No module named 'knock-feature-selection'  Hi...: No module named 'knock-feature-selection' How to remove the ModuleNotFoundError: No module named 'knock-feature-selection' error? Thanks   
JTable - Cell selection - Swing AWT
(ListSelectionModel.SINGLE_SELECTION); JScrollPane spane = new JScrollPane(table
Selection Sort In Java
Selection Sort In Java      ... are going to sort the values of an array  using selection sort.In selection sorting.... Sort the remaining  values by using same steps. Selection sort 
image scrolling
image scrolling  A brief description of scrolling image
Image Steganography
Image Steganography  SOURCE CODE FOR IMAGE STEGANOGRAPHY
Program Arrow selection Most Urgent - JSP-Servlet
Program Arrow selection Most Urgent  Respected Sir/Madam, I am R.Ragavendran.. I got your coding which is highly appreciable.. As per my requiremennt,there are image buttons for each row in the database.. But i am

Ads