|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Building GUI based applicationI 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 |
|
|
Re: Building GUI based application> 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 > What do you mean with "unable" ?. Could you be more explicit, with exceptions you got or something to have an idea what is going on ?. Regards, Diego. |
|
|
Re: Building GUI based applicationMuhammad,
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... ---------------------------------- |
|
|
Re: Building GUI based applicationsean,
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, -- Muhammad Ali http://techboard.wordpress.com Software Engineer - E2ESP muhammadaliamin(at)gmail(dot)com |
|
|
Re: Building GUI based applicationMuhammad,
See the answers inline, below... alee amin wrote: > 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. application come down to personal preferences. Personally, I simply create a vanilla Java Application Project, with nothing more than a Main class, and build my entire application from scratch. But, that's my personal preference, as it gives me more control over the final application. > > 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? The only way that I know how to "bind" the property is to use the JFileChooser.setSelectedFile() method. This method takes a File object as a parameter, so you could do the following: JFileChooser getFile = new JFileChooser(bean.getTextProperty.toString()); // "binds" the property using the constructor. getFile.setSelectedFile(new File(bean.getTextProperty.toString())); // "binds" the property at a later point after the JFileChooser has already been created. These two methods are the only way that *I* know to "bind" the property to the text field on the JFileChooser object. I don't know if this is what you were looking for, but this is how I do it. As I said in my answer to question 1, I like to have total control over my application, so I take care of most things via code...I think it comes from my background in other languages. ;-) -- Cheers, Sean Carrick PekinSOFT Systems sean@... http://www.pekinsoft.net ---------------------------------- Proud to be 100% Microsoft free... ---------------------------------- |
|
|
Re: Building GUI based applicationsean,
again i am really thankful to you for your detail reply. well I have been in conversation with senior members of our team and i was already trying to say 'em to build things from scratch but they are not willing. so i am still looking around for some other solutions. your text really helped me for my discussion but i'll still look for some NB/SWT or some other framework solution. On Thu, May 8, 2008 at 6:47 PM, Sean Carrick <seansitsolutions@...> wrote: Muhammad, -- Muhammad Ali http://techboard.wordpress.com Software Engineer - E2ESP muhammadaliamin(at)gmail(dot)com |
|
|
Re: Building GUI based applicationSwing is what you get with netbeans. I've never heard swt plugins or framework for netbeans.
If you like swt then you can go with eclipse. But I'm curious, does the sample code given by sean not solved your problem ? Also check out the JFileChooser documentation. 2008/5/9 alee amin <mailing.list.mail.id@gmail.com>: sean, |
| Free Forum Powered by Nabble | Forum Help |