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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


suneel
retaining save dialog box even after clicking save button
2 Answer(s)      6 years 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
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
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 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
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
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
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
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
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 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
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
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
Advertisements
 

 

 

DMCA.com