Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners retaining save dialog box even after clicking save button

Have Programming Question? Ask it here!
 
 
 


suneel
retaining save dialog box even after clicking save button
2 Answer(s)      5 years and 10 months ago
Posted in : Java Beginners



Advertisement
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
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
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
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
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
. at the end of the interview, use a dialog box to ask whether the user wants
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
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
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
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
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
jquery dialog box center
jquery dialog box center  How to create dialog box with center alignment in jquery..?   $('my-selector').dialog('option', 'position', 'center
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
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 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
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
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
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
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
Show Dialog Box in Java
by clicking the "Ok" button. A message dialog box which has two or three... the message Dialog box. Our program display "Click Me" button on the window... box as follows: A simple message dialog box which has only one button
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
Save a pdf with spring as below code
Save a pdf with spring as below code   c:/report.pdf All work in the same way, but never save the report to disk. How to solve this problem? please reply me
save list of objects in Spring and hibernate
save list of objects in Spring and hibernate  I use a javascript which add dynamic rows with values in jsp. Now i want to save these multiple values using spring and hibernate. Thanks for help
save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening... and save this amount until he changes it again. Thank You
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening... and save this amount until he changes it again. Thank You
Save the input data until user get changed
Save the input data until user get changed  I would like to know how to store the give input data and perform the calculations even after re-opening... and save this amount until he changes it again. Thank You
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am using applet and creating a chart by jcchart. Now when the chart has ploated If user want to export this chart as GIF format then this chart should be save
How to save image on the server by applet
How to save image on the server by applet  HI, in my project I am using applet and creating a chart by jcchart. Now when the chart has ploated If user want to export this chart as GIF format then this chart should be save
session_save_path()
session_save_path() session_save_path() command returns the current working directory path.  Syntax session_save_path(); Example: <?php echo session_save_path(); #return the current working directory path ?>  
save output in multiple text files
save output in multiple text files  Hi..I'm getting problem to store the output of this php code into multiple text files. Can anyone sugeest. Here is my code: <?php for($i=1; $i<=100; $i++) { $html = file_get
Show input dialog box
. The input dialog box contains two buttons, first is the "Ok" button.... If you click on the button then a input dialog box will open. If you click on the "Ok" button of the input dialog button then a message dialog box
Full path of image to save it in a folder
Full path of image to save it in a folder  Sir ,I am trying to upload a file but only sends file name as parameter. I want a code that would help me to find that image path &upload it as well. I am just a beginner in jsp
Advertisements
 

 

 

DMCA.com