Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2008, 09:14 PM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default Dumb Netbeans Q
I've made a program that basicall serves as a music organizer. Import iTunes playlist. Remove duplicates. Edit stuff. Create new playlists. Previously it just used System.out.println to display the playlists. Now I found the joy (curse) of Netbeans and made a pretty GUI for the whole thing.

There is a class for reading text playlists, adding and showing music etc. Another one for extra sundry methods and then the new class for the JFrame Gui.

I want to put a button in the JFrame to open a JFileChooser window to select a file to import.

A made a new class for the FileChooser... But I have no idea how to make it go when I click the button...

I've tried some things already but I can't get it to work.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-23-2008, 05:26 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
After adding the JFileChooser component add an action event to it. Get the action text and do the process.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-23-2008, 10:13 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
Default
here is some hints

1. Add a ActionListener
2. Get the return value of the JFilechooser (it can be OK or the Cancel button)
Sample in getting the return value:
Code:
int RT = fileChooser.showOpenDialog(this);
3. Compare the return value to your desired value
Another Sample:
Code:
 if (RT == JFileChooser.APPROVE_OPTION){
//do your thing here for Yes or Ok button
} else if (RT == JFileChooser.CANCEL_OPTION){
//here is for Cancel or No button
}
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-23-2008, 03:05 PM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
Thanks, I will try those ideas.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-24-2008, 06:31 PM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
I got it to show the FileChooser window, and return a file. The only problem is that it doesn't return the full directory path (I'm using Windows).

I made a class based on a JInternalFrame called Browse, and the JFileChooser in this class I called browser.

Here is my code:

Browse br = new Browse();
br.browser.showOpenDialog(null);
File selection = br.browser.getSelectedFile());

What method can I use to return the entire path?

Thanks again for your help.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-25-2008, 06:03 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
getSelectedFile() gives the full path.

What's your browser class do? I can't see nay file chooser instance here in your code segment.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-25-2008, 09:21 AM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
That's just the bit of code that executes when the specific button is clicked.

The Browse class is a JInternalFrame with a JFileChooser called browser in it. That's it.

So I created a new object of the Browse class:
Browse br = new Browse()
Then I used the showOpenDialog method to show the JFileChooser called browser.
Then I used the getSelectedFile method to return the selection made in browser.

It all works perfectly, but it returns only the filename.
i.e. Instead of returning D:\lists\songs.txt it just returns songs.txt
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-25-2008, 11:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Try to use getCurrentDirectory() to find the initial directory there.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-25-2008, 01:35 PM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
That only returns the immediate directory that the selected file is in.

i.e. If the selected file was: C:\files\lists\songs.txt
then getCurrentDirectory returns lists, and getSelectedFile returns songs.txt

Surely that isn't how it's suppose to be, because this makes it quite useless...
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-26-2008, 04:25 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Can I look at your code. I'm not sure what's going on there.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-26-2008, 09:42 AM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
Sorry it's so much.
I wasn't sure what you wanted exactly...

Thanks again for your help.

Code:
package MusicMan;

public class Start extends javax.swing.JFrame
{
    Action ac = new Action(); //the Action class has all of the important methods

    public Start()
    {
        initComponents();
    }//dc
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        btnImport = new javax.swing.JButton();
        btnPlaylist = new javax.swing.JButton();
        labelOutput = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        list = new javax.swing.JList(ac.displayLists());
        labelPlaylists = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        output = new javax.swing.JList();
        btnEdit = new javax.swing.JButton();
        browse = new javax.swing.JButton();
        btnManual = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(10, 10, 10, 10));
        setMaximizedBounds(new java.awt.Rectangle(0, 1, 0, 1));

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, btnImport, org.jdesktop.beansbinding.ELProperty.create("MusicMan"), this, org.jdesktop.beansbinding.BeanProperty.create("title"));
        bindingGroup.addBinding(binding);

        btnImport.setText("Import Songs");
        btnImport.setToolTipText("Import songs from a text file");
        btnImport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportActionPerformed(evt);
            }
        });

        btnPlaylist.setText("Add Playlist");
        btnPlaylist.setToolTipText("Select songs first");
        btnPlaylist.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPlaylistActionPerformed(evt);
            }
        });

        labelOutput.setFont(new java.awt.Font("Courier New", 0, 12));
        labelOutput.setLabelFor(output);
        labelOutput.setText("Name                                  |  Artist                                |  Album                                 |  Date Added ");
        labelOutput.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        list.setFont(new java.awt.Font("Courier New", 0, 12));
        list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        list.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(list);

        labelPlaylists.setLabelFor(list);
        labelPlaylists.setText("Playlists");
        labelPlaylists.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        output.setFont(new java.awt.Font("Courier New", 0, 12));
        jScrollPane1.setViewportView(output);

        btnEdit.setText("Edit Song Info");
        btnEdit.setToolTipText("Select songs first");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        browse.setText("Import iTunes Playlist");
        browse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseActionPerformed(evt);
            }
        });

        btnManual.setText("Manual Song Add");
        btnManual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnManualActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(labelPlaylists, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(labelOutput, javax.swing.GroupLayout.DEFAULT_SIZE, 1044, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1052, Short.MAX_VALUE)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(browse)
                        .addGap(18, 18, 18)
                        .addComponent(btnManual)
                        .addGap(18, 18, 18)
                        .addComponent(btnPlaylist)
                        .addGap(18, 18, 18)
                        .addComponent(btnEdit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 421, Short.MAX_VALUE)
                        .addComponent(btnImport)
                        .addGap(173, 173, 173))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(browse)
                    .addComponent(btnPlaylist)
                    .addComponent(btnEdit)
                    .addComponent(btnManual)
                    .addComponent(btnImport))
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelPlaylists)
                    .addComponent(labelOutput))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(390, 390, 390))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 692, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnImportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportActionPerformed
    ac.addMusicFromText("songs.txt");
    output.setListData(ac.showMusic(0));
}//GEN-LAST:event_btnImportActionPerformed

private void btnPlaylistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPlaylistActionPerformed
    output.setListData(ac.showMusic(ac.addPlaylist(output.getSelectedIndices())));
    list.setListData(ac.displayLists());
}//GEN-LAST:event_btnPlaylistActionPerformed

private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
    output.setListData(ac.showMusic(list.getSelectedIndex()));
}//GEN-LAST:event_listMouseClicked

private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
    ac.edit(output.getSelectedIndex());
    output.setListData(ac.showMusic(0));
}//GEN-LAST:event_btnEditActionPerformed

private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed
    Browse br = new Browse();
    br.browser.showOpenDialog(null);
    ac.addMusicFromText(br.browser.getName(br.browser.getSelectedFile()));
    output.setListData(ac.showMusic(0));
}//GEN-LAST:event_browseActionPerformed

private void btnManualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnManualActionPerformed
    SongEntry se = new SongEntry(new Start(), true);
    se.setVisible(true);
    ac.addMusic(se.nameEntry.getText(), se.artistEntry.getText(), se.albumEntry.getText());
    output.setListData(ac.showMusic(0));
}//GEN-LAST:event_btnManualActionPerformed

    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new Start().setVisible(true);
            }
        });
    }//main

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browse;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnImport;
    private javax.swing.JButton btnManual;
    private javax.swing.JButton btnPlaylist;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel labelOutput;
    private javax.swing.JLabel labelPlaylists;
    private javax.swing.JList list;
    javax.swing.JList output;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
Code:
package MusicMan;

public class Browse extends javax.swing.JInternalFrame {

    public Browse() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        browser = new javax.swing.JFileChooser();

        browser.setFileHidingEnabled(false);
        browser.setDragEnabled(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(browser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(browser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JFileChooser browser;
    // End of variables declaration//GEN-END:variables

}
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-26-2008, 09:44 AM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
The important stuff is in BOLD.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-26-2008, 09:45 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
Default
I used this command to get the file with the Current directory


Code:
filename=fileChooser.getSelectedFile();
I hope that helps.
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-26-2008, 09:49 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Yes it should works. But our friend says it not work. Seems something wrong with Browser implementation or else.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-26-2008, 09:54 AM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
Hmm...
Quite strange then...

I think I'll make a new test prog, just with the essential JFileChooser and see if it works...
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-26-2008, 10:02 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 6,525
Rep Power: 9
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Ya, that's better. Then you can compare two applications and find the difference.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Someone helped you?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.
Help:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Resources:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Web:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Tips:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 05-26-2008, 10:08 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 234
Rep Power: 2
Eku is on a distinguished road
Default
hmmm. . . I cant seem to undestant the code. im sorry. Im a little sick. The return value of the .getSelectedFile() is in file data type. If you want to use it as string you should convert it toString first. Sorry if i cant give much help.

Code:
else if(command.equalsIgnoreCase("Save As")){
            result = fileChooser.showSaveDialog(this);
            if (result == JFileChooser.CANCEL_OPTION) {
                return;}
            filename=fileChooser.getSelectedFile();
            ext = fileChooser.getFileFilter();
            Save();
}
Here is a sample. i got the filename with the directory using getSelectedFile();
and got the extention using the getfilterfile. *Note: You must declare a filter if you want to filter the extensions. Then call my Function.
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 05-26-2008, 02:58 PM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
I used the getName method to convert it to a string...

What is getFileFilter for? It already returns the file extension (.txt).

I'm on my phone now, but later at my PC I'll try your code out. (and try a new one, so I can see where the problem might have been in my case...)
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 05-26-2008, 04:15 PM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
I just had a look at the Java API.

This is what it says about file filters:
Quote:
The file filter is used by the file chooser to filter out files from the user's view.
I don't think that's what I need...

Will still try your reccommendation later on.
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 05-26-2008, 09:29 PM
Senior Member
 
Join Date: Nov 2007
Posts: 121
Rep Power: 0
carderne is on a distinguished road
Default
I realised what the problem was. The getName() method only used the filename, not the entire path. So I changed it to just use getSelected() and keep it as a File type.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
i am a dumb dumb goose_01ca New To Java 4 04-25-2008 04:44 AM
NetBeans 5.5 Ry4n NetBeans 3 01-26-2008 06:09 AM
NetBeans 5.5.1 Help. padutch2 New To Java 6 12-03-2007 03:01 AM
netbeans 64 bit caspermel NetBeans 1 06-26-2007 10:29 PM
About using netbeans yuchuang NetBeans 3 05-27-2007 08:06 PM


All times are GMT +2. The time now is 09:26 PM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org