Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
So I am trying to open a file using JFileChooser... What does the Open button return? Do i have to set a actionListener for it? Because there is a Open button there by default in OS X. Any idea how to set an actionListener to something that is already created?
 

bousozoku

Moderator emeritus
Jun 25, 2002
16,120
2,397
Lard
I'm not sure what the return code since I haven't looked it up recently. Here is a sample of my code where I'm trying to get the path to a file.

Code:
  public void protein1MouseClicked(java.awt.event.MouseEvent e)
  {

    JFileChooser fc = new JFileChooser();

    int returnCode = fc.showDialog(FPFrame.this, "Select");
    if(returnCode == JFileChooser.APPROVE_OPTION)
    {
      file1 = fc.getSelectedFile();
    }
  } // end protein1MouseClicked()
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
bousozoku said:
I'm not sure what the return code since I haven't looked it up recently. Here is a sample of my code where I'm trying to get the path to a file.

Code:
  public void protein1MouseClicked(java.awt.event.MouseEvent e)
  {

    JFileChooser fc = new JFileChooser();

    int returnCode = fc.showDialog(FPFrame.this, "Select");
    if(returnCode == JFileChooser.APPROVE_OPTION)
    {
      file1 = fc.getSelectedFile();
    }
  } // end protein1MouseClicked()

I am with you until FPFrame.this, what exactly is that? What componet?
 

tuc

macrumors 6502
Aug 25, 2003
333
67
JFileChooser vs. FileChooser

btw, you might want to use a java.awt.FileChooser
instead of JFileChooser. You get the OS native widget
instead of an approximation.
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
If your app is in Swing, then keep it all swing, and stick with JFileChooser.

The JFrame argument to the JFileChooser allows it to attach the JFileChooser dialog onto that JFrame, so it can modally block input to the JFrame.
 

bousozoku

Moderator emeritus
Jun 25, 2002
16,120
2,397
Lard
tuc said:
btw, you might want to use a java.awt.FileChooser
instead of JFileChooser. You get the OS native widget
instead of an approximation.

The extra behaviours that come with JFileChooser far outweigh its not being native. Besides, AWT-based applications probably still don't look the same deployed on a number of platforms. :(
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
No worries, i have written my own little Client appy... It is hidious.. I have never been to good at the GUI stuff.. Anyone suggest some good GUI hints?
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,629
Western US
If you're doing anything with Swing, I highly recommend the book Core Java Foundation Classes by Kim Topley. This book is fantastic and saved me a lot of pain back when I was learning Swing programming. IF it's still in print/available, not sure about that. I'm not doing Java development today, but if I were, I know I'd still be referencing this book.
 

jtalerico

macrumors 6502
Original poster
Nov 23, 2005
358
0
Yeah, I am not in school right now. I am doing a coop here in Raleigh. I am trying to teach myself some stuff, and build myself a program that I can use :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.