| | |
open local folder with a jButton
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 27
Reputation:
Solved Threads: 0
Good evening,
I am trying to simply open a folder located on my local C:\ drive, to be exact just for testing purposes I am trying to open C:\temp folder.
What I have is a JFrame with a single Jbutton and some code, however when I execute the button, nothing absolutely nothing happens, it doesn't crash, it doesn't open a folder, it doesn't give me a message error.
line 65 to 85 is where my code resides.
under the "private void jButton1ActionPerformed" I call a "OpenMain();" method which I define right under that starting on line 69.
I would definitly appreciate some help,
John
My code:
I am trying to simply open a folder located on my local C:\ drive, to be exact just for testing purposes I am trying to open C:\temp folder.
What I have is a JFrame with a single Jbutton and some code, however when I execute the button, nothing absolutely nothing happens, it doesn't crash, it doesn't open a folder, it doesn't give me a message error.
line 65 to 85 is where my code resides.
under the "private void jButton1ActionPerformed" I call a "OpenMain();" method which I define right under that starting on line 69.
I would definitly appreciate some help,
John
My code:
java Syntax (Toggle Plain Text)
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * NewJFrame.java * * Created on Jul 4, 2009, 6:57:23 PM */ package systems; /** * * @author olivier */ public class NewJFrame extends javax.swing.JFrame { /** Creates new form NewJFrame */ public NewJFrame() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton1.setText("jButton1"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(154, 154, 154) .add(jButton1) .addContainerGap(173, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(86, 86, 86) .add(jButton1) .addContainerGap(191, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { OpenMain(); } private void OpenMain() { try { //Path for folder or file that you want to open //In my case i will open C:\ drive //So create a String like below //Don't forget to change \ to \\ String a="C:\\temp"; //Execute command //Command that you must know : rundll32 SHELL32.DLL,ShellExec_RunDLL File_Or_Folder_To_Open Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL \""+a+"\""); } catch(Exception exception) { exception.printStackTrace(); } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewJFrame().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; // End of variables declaration }
Use following code
Java Syntax (Toggle Plain Text)
String a="C:\\csnet"; Runtime.getRuntime().exec("cmd /c start "+a);
![]() |
Similar Threads
- Unable to Open Local Disk (C:) and (D:) (Windows NT / 2000 / XP)
- Upload a file to a local folder (Visual Basic 4 / 5 / 6)
- Open local file from webpage (JavaScript / DHTML / AJAX)
- Please help me not able to open local drives (Viruses, Spyware and other Nasties)
- Virus Changed my registration and cant open my Local policy settings (Viruses, Spyware and other Nasties)
- Getting Firefox to Launch "Open Containing Folder" in Konqueror (*nix Software)
Other Threads in the Java Forum
- Previous Thread: JComponent Placement
- Next Thread: getting nullpoint exception again
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie objects online oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu windows working






