| | |
open local folder with a jButton
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);
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
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 |
addball android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) button card class classes client code collision columns component constructor crashcourse css database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loan loop method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program programming project radio scanner server service set sharepoint smart sms smsspam software sql subclass support swing textfield threads tree trolltech unlimited utility windows






