« Return to Thread: Building GUI based application

Re: Building GUI based application

by DanglingChap :: Rate this Message:

Reply to Author | View in Thread

sean,

Thanks a lot for such a help full reply .. :)..

1: now a days i am going through some evaluation period for some platform. Earlier solution was to build a GUI based solution using SWT, but it has lesser VISUAL support in NB. So i was thinking to use NB Platform for which i am unable to find proper resources. What you suggest. What kind of platform we use for Desktop Based application in Java.

2: thanks for explaining the binding of events with JFileChooser. But i was trying to bind a bean property to JFileChooser text field. so that what ever string that property (a field of class) contains it is displayed in JFileChooser textfield and on "Browse" button it should select that file by default. We can do it manually but isn't there any way that we *bind* it with JFileChooser properties?


On Wed, May 7, 2008 at 5:44 PM, Sean Carrick <seansitsolutions@...> wrote:
Muhammad,

To use the JFileChooser, you just need to right click on the button in Design view and click on the Events...Actions...ActionPerformed command.  This will place you into the Source view and create a skeleton of the JButtonActionPerformed(ActionEvent evt) event handler method.

Inside of that event handler, place the following code:

 // Show a file browse dialog, set to show only folders, to allow the user
 // to visually locate where s/he would like to install the program.
 if ( System.getProperty("os.name").contains("Linux") ) {
  this.selectFile = new JFileChooser("/usr/local/");  // Default for Linux
 } else if ( System.getProperty("os.name").contains("Windows") ) {
  this.selectFile = new JFileChooser("C:\\Program Files\\"); // Standard for Windows
 } // end of this.selectFile creation.

 // Only allow folders to be selected.
 this.selectFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

 // Set the title for this.selectFile.
 this.selectFile.setDialogTitle("Select Installation Path");

 // Show the selectFile modally.
 int choice = this.selectFile.showOpenDialog(this);

 if ( choice == JFileChooser.APPROVE_OPTION ) {
  this.txtInstallationPath.setText(
        this.selectFile.getSelectedFile().toString());
 }

 if ( System.getProperty("os.name").contains("Linux") ) {
  this.txtInstallationPath.setText(
        this.txtInstallationPath.getText() +
        "/loe");
 } else if ( System.getProperty("os.name").contains("Windows") ) {
  this.txtInstallationPath.setText(
        this.txtInstallationPath.getText() +
        "\\Law Office Essentials");
 }
                              This is a snippet from a GUI installer I'm writing for one of my projects.  A lot of what is going on is specific to my application, but it gives you the gist of how to use the JFileChooser bean within a JButton's event handler.

In the previous code, "selectFile" is a class-level private field of the type JFileChooser.  I have numerous "browse" buttons (next to text fields with an ellipsis (...) on them) to allow the user to visually navigate to a location, instead of having to type it in the text fields.  Therefore, I only wanted to create the one object, then I initialize it in each browse button's action event handler.  This helps to save on resources, as I don't have numerous JFileChooser objects sucking up memory.  An alternative way of using the JFileChooser is to access its members directly.  Personally, I find it clearer to do as I have done, by creating an instance of the JFileChooser.  The setFileSelectionMode allows you to limit what is allowed to be selected.  In this instance, I want the user to only be able to choose directories, so I gave it the JFileChooser.DIRECTORIES_ONLY option.  You can limit or expand this mode as you desire through the JFileChooser's enumeration.
For more information, see the JavaDoc for the Sun Java API, located here:
http://java.sun.com/javase/6/docs/api/

Cheers,

Sean Carrick
PekinSOFT Systems
www.pekinsoft.net


alee amin wrote:
I am trying to build GUI based application in NetBeans 6. But i am unable to start through. I have used the online tutorials from netbeans sites but those are not helping me much. I am unable to bind some controls with classes (beans) like JFileChooser etc. Can someone guide me in detail

--
Muhammad Ali
http://techboard.wordpress.com
Software Engineer - E2ESP
blackishbubble(at)gmail(dot)com

--

Cheers,

Sean Carrick
PekinSOFT Systems
sean@...
http://www.pekinsoft.net

----------------------------------
Proud to be 100% Microsoft free...
----------------------------------




--
Muhammad Ali
http://techboard.wordpress.com
Software Engineer - E2ESP
muhammadaliamin(at)gmail(dot)com

 « Return to Thread: Building GUI based application