retaining save dialog box even after clicking save button

retaining save dialog box even after clicking save button

View Answers

October 29, 2008 at 3:13 PM

Hi friend,


Plz give full details with source code to solve the problem and specify the technology used Java/Jsp/Servlet/Struts/JSF etc.


Thanks

November 1, 2008 at 8:58 AM

Thanks for ur concern.I have got my answer to my problem.I made a SSCCE for my problem.It is as below

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.filechooser.*;
public class Frame
{
static JTextArea textArea=new JTextArea("",5,40);
static JMenuItem menuItem;
public static void main(String args[])
{

JFrame frame = new JFrame("Notepad");
JMenuBar menuBar;
JMenu menu;
int rows=400,cols=100;

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JLabel emptyLabel=new JLabel("");
emptyLabel.setPreferredSize(new Dimension(475, 400));
frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

frame.pack();

menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);

menu = new JMenu("File");
menu.setMnemonic(KeyEvent.VK_F);
menuBar.add(menu);

menuItem = new JMenuItem("Save",KeyEvent.VK_S);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
menuItem.addActionListener(new Listener());

menu.add(menuItem);

JScrollPane scrollPane = new JScrollPane(textArea);
textArea.setEditable(true);

frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.getContentPane().setPreferredSize(new Dimension(rows, cols));

frame.setVisible(true);
}
public static class Listener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
File file;
int returnVal;
int flag;
do
{
flag=0;
final JFileChooser fc = new JFileChooser();
file = fc.getSelectedFile();
//here when i put it in do while loop it opens from MY DOCUMENTS which i dont want..it must retain its previous location
returnVal = fc.showSaveDialog(menuItem.getParent());
if (returnVal == JFileChooser.APPROVE_OPTION)
{
try
{
file = fc.getSelectedFile();
String[] files=new File(file.getParent()).list();
for(int i=0;i<files.length;i++)
{
if(files[i].compareTo(file.getName())==0)
{
int response = JOptionPane.showConfirmDialog(null, "File name u gave already exists\ndo u want to replace it now??");
if(response==1)
{
flag=1;
System.out.println("Dont replace file");
}
}
}
}catch(Exception e1){};
}
}while(flag==1);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
try
{
String fileName = file.getName();
Writer output=null;
output=new BufferedWriter(new FileWriter(file));
output.write(textArea.getText());
output.close();
}catch(Exception e2){};
}
}
}

}

I every time called a new instance of FileChooser.So i couldn't retain its state.Now i made it an instance so that its state is retained in my entire application.Thanks for reading this....:)









Related Tutorials/Questions & Answers:
retaining save dialog box even after clicking save button - Java Beginners
retaining save dialog box even after clicking save button  I am... get it back??(even if i cal save dialog box again it would open again from... when i open save dialog box and input a file name that is already present
how to add save,discard,& cancel button in a message box - Struts
how to add save,discard,& cancel button in a message box  how to add save,discard,& cancel button in a message box
Advertisements
save excel file with save and open dilog box
save excel file with save and open dilog box  following is my jsp code it is working correct.. i want to save excel file throgh jsp bt not by hard...");) user should have freedom to save the file in any location so plz give me
Save,Discard and Cancel button - Struts
Save,Discard and Cancel button   How can I create a confirm message with Save,Discard and Cancel button instead of OK/Cancel buttons in java script inside a jsp
Should not logout after clicking the back/forward button
Should not logout after clicking the back/forward button  Hi all I have wrote a code for login now. User is able to login but after logging in when he clicks on the back button user automatically gets logged out. very next
How to save image after edit in php
How to save image after edit in php  Hello, I have create a simple image editor with the effected of brightness, contrast, and desaturat etc. I have...="220" height="277" name="image1"> <button value="pixastic-desaturate
Save the content in my wysiwyg editor into specified location of user when clicked on save button in my web page
Save the content in my wysiwyg editor into specified location of user when clicked on save button in my web page  I am using wysiwyg editor... someone help how to code to save this wysiwyg content into word document
How to save form fields into the MySql Database without submit button in jsp?
How to save form fields into the MySql Database without submit button in jsp?  I want to store user inputs into the database using javasccript or ajax or jqury but without submit button. Form Contains three fields
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog
create text box by clicking button and submittong text in text box using submit
create text box by clicking button and submittong text in text box using submit  Hi, I created a button when i click on button new textbox... box in SOP). i also want the text box should generate in front of NEW button
how to capture IE browser FileDownload box open ,save and cancel event - JSP-Servlet
how to capture IE browser FileDownload box open ,save and cancel event ... in response object.B/C of this ,browser fileDownload dialog box comes.we need to capture open,save and cancel event of filedownload box in javascript. Please
Popup dialog box in java
= new JFrame("Show popup Dialog Box"); JButton button = new JButton("Click to viw dialog box"); button.addActionListener(new MyAction()); frame.add(button... button.On clicking your dialog box will appear. JoptionPane class is used here
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box  hello. write an application that displays a series of at least four interview questions and each question should have at least three possible numeric choice answers. at the end of the interview, use a dialog box
dialog box
dialog box to ask to quit or continue  hello. write an application that displays a series of at least four interview questions and each question... of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
dialog box to show latest question  hello. write an application that displays a series of at least four interview questions and each question should... of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
of the interview, use a dialog box to ask whether the user wants to - enter another set
dialog box
. at the end of the interview, use a dialog box to ask whether the user wants
dialog box
. at the end of the interview, use a dialog box to ask whether the user wants
How to Display Next question from database after clicking Next Button using "Arraylist concept"
How to Display Next question from database after clicking Next Button using "Arraylist concept"  </tr> <%if (pageName.equals("1")) {%> <tr> <td> <div style
dialog box size allignment
dialog box size allignment  actually i have 1 button,when clicked on it has to show dialog box containing 14 rows and 3 columns(jtextfield and jlables). i added action listener.is it working fine.but when i resized the dialog
dialog box
dialog box  hi.write an application containing three parallel arrays that hold 10 elements each.the first array holds four digits student ID numbers... averages. use dialog boxes to accept a student ID number and display the student's
jquery dialog box center
jquery dialog box center  How to create dialog box with center alignment in jquery..?   $('my-selector').dialog('option', 'position', 'center
ModuleNotFoundError: No module named 'save'
install save After the installation of save python library...ModuleNotFoundError: No module named 'save'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'save
Hibernate save()
This tutorial explain how save() works in hibernate
upload and save the file
upload and save the file  upload and save a file from a computer to specific location of remote computer using jsp
Save Table - SQL
Save Table  Where Oracle Tables or Database is saved? How to see Oracle Tables ? What are the websites to learn step by step Oracle. Help Me
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
How to save value in JSP
How to save value in JSP  Employee Name Time-IN Time-OUT Date t1 9 7 2012-12-12 t2... 324 2012-12-12 save i want to save dis value jsp to action ...how
save uiimage to photo library
save uiimage to photo library  How to saved the clicked picture...; Save UIImage to photo library Creating a camera application in iPhone need three simple steps to follow? 1) Role Camera 2) Save the captured image
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page or download.. that depend on user wish how to make this page save or download <
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page or download.. that depend on user wish how to make this page save or download <
save data DAO
save data DAO  how to save data in db   package com.tcs.ignite.dao; import com.tcs.ignite.bean.User; import com.tcs.ignite.connection.Connectiondetails; import java.sql.ResultSet; import java.sql.SQLException; import
Information Save Alert
Information Save Alert  Hi, Sir I am creating a web page there user can edit their information. I want a javascript that can show an alert message when user edit the information and trying to close or go to another page without
How to save file in vi editor?
:w to save the file Type :wq to save and quit Type :q! to quit without saving...How to save file in vi editor?  Hi, I am trying to find commands to save the file in the vi editor? Can anyone show me the example and explain me
Show Dialog Box in Java
can finish the message dialog box by clicking the "Ok" button... the message Dialog box. Our program display "Click Me" button on the window... message dialog box which has only one button i.e. "Ok". This type
How to save data - Swing AWT
How to save data  Hi, I have a problem about how to save data ,but first before data save to dababase, data must view in jLisit or Jtable then in jList or or Jtable many data viewer in one button,then another button must
Display alert box on clicking link
Display alert box on clicking link In this tutorial, we will display alert box... a "a href" link. On clicking this link ,a alert box prompt message... in the block. The code given below is used to display alert box on clicking link
ModuleNotFoundError: No module named 'overlap-save'
with following command: pip install overlap-save After the installation...ModuleNotFoundError: No module named 'overlap-save'  Hi, My Python... 'overlap-save' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'pip-save'
command: pip install pip-save After the installation of pip-save python...ModuleNotFoundError: No module named 'pip-save'  Hi, My Python...-save' How to remove the ModuleNotFoundError: No module named 'pip-save
ModuleNotFoundError: No module named 'save-experiences'
-experiences python with following command: pip install save-experiences After...ModuleNotFoundError: No module named 'save-experiences'  Hi, My... named 'save-experiences' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'save_skype'
with following command: pip install save_skype After the installation of save...ModuleNotFoundError: No module named 'save_skype'  Hi, My Python... 'save_skype' How to remove the ModuleNotFoundError: No module named 'save
ModuleNotFoundError: No module named 'Save-to-DB'
with following command: pip install Save-to-DB After the installation of Save...ModuleNotFoundError: No module named 'Save-to-DB'  Hi, My Python... 'Save-to-DB' How to remove the ModuleNotFoundError: No module named 'Save
Record and Save Video using Java
Record and Save Video using Java  How to record video(webcam) and save it using Java.?? Its really urgent
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem

Ads