Hello all.
I've had a look across the forums and I can't seem to find an answer to my particular problem, although changing text in fields and frames seems a "common" issue (and not one that I am having).
So I have a package with a number of <sub Packages>
first off I have created a GUI with a number of fields in it that I need a user to change (they hold the path name to a file).
I have a button that I click which opens up a <standard> file selector GUI (in fact it is a minor modification of one in tutorials from here
fileChooser.
So my main GUI calls to create a copy of the file chooser GUI.
During the operation of the I can hapily call the fileChooser, an go through and select a file.
I want to change the operation of the <saveButton> so as it will pass the name of the file that I have selected into a JTextField in the calling (parent) gui.
So here it is in kindof pseudo code.....
class HandlerFrame
{
//instance variable
protected javax.swing.JTextField SourceFileNameField;
//later initialised with the JFrame as
private void initComponents()
{
//obviously I am initialising all my other components, so I've left them off as they don't concern the rest //of the function??? I don't think!?
SourceFileNameField = new javax.swing.JTextField()
SourceFileNameField.setText("Full Path to Source file");
SourceFileNameField.setToolTipText("Select source file");
}
}//end handler frame class
public class FileChooser extend extends JPanel implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == saveButton)
{
int returnVal = fc.showSaveDialog(FileChooser.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
//This is where a real application would save the file.
log.append("Saving: " + file.getName() + "." + newline);
SourceFileNameField.setText(file.getAbsolutePath());
}
else
{
log.append("Save command cancelled by user." + newline);
}
log.setCaretPosition(log.getDocument().getLength());
}
}//end FileChooser....
so the line
< SourceFileNameField.setText(file.getAbsolutePath()); >
doesn't update the value of the JTextField??
I'm sure I'm missing something blatantly obvious, but as yet I haven't found it!
I've changed the value of the access from private to protected....
so do I need to override the < setText() > method, and then reference to it directly??
in fact I'm going to try that now... or rather when I get home, I'll add in a method
setSourceFileNameText(String S)
{
this.SourceFileNameField.setText(S);
}
and test it at home tonight......
I'll report back, therwise am I gong to have to turn my FileChooser class into an inner class, so as to have access to the members (fields) of my FileHandlerGUI class??
any pointers or assistance will be hugely appreciated
Thanks in advance.
David
----------------------------------edit-------------------------------------
Ok so I've tried writing a static method inside the parent class < HandlerFrame >. but that seems to have made no difference....
Later today I'm going to play with creating the whole thing of the < fileChooser > class as an inner class... again I'll report back on the success (or otherwise!), I'm not very confident on inner classes, and I allways had the impression that anything you can do with an inner class you can do with a "normal" class....
I've just had another thought.... could I get this to work by using the < HandlerFrame > class as part of what makes up a < fileChooser > (have the HandlerFrame being a member of my fileChooser) - or maybe vice versa
I also take it, by observation of the number of people that have read this thread, that I'm either not very clear in the explanation of what I am atteming to do, or I'm trying to do something very strange and no-one has the foggiest as to why I would want to do this in the first place!
if you want clarification please just ask ( although the weekend is almost upon us so I may go quiet for a couple of days ).
I could post the whole of my code.... unfortunately it is residing on a different computer and it doesn't have internet access (and the USB port on my external HDD has given up - I'm waiting on a USB - to- eSATA conversion cable so as I can start using it again via the eSATA port).
As before, I look forward to your comments / suggestions / assistance.
David
Edited by: IAmDave on 16-Sep-2009 13:18