How to make FileChooser only  have a Folder to choose?PLs help

Dear Java expert!!Anyone know how to make user to choose it content from a single folder only...Pls advice
this is my program..
`````````````````````````
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class Test2 extends JFrame {
     JFileChooser chooser = new JFileChooser();
     TextPreviewer previewer = new TextPreviewer();
     JPanel previewPanel = new PreviewPanel();
     class PreviewPanel extends JPanel {
          public PreviewPanel() {
               JLabel label = new JLabel("Text Previewer",
                                             SwingConstants.CENTER);
               setPreferredSize(new Dimension(250,0));
               setBorder(BorderFactory.createEtchedBorder());
               setLayout(new BorderLayout());
               label.setBorder(BorderFactory.createEtchedBorder());
               add(label, BorderLayout.NORTH);
               add(previewer, BorderLayout.CENTER);
     public Test2() {
          super("Accessory Components");
          Container contentPane = getContentPane();
          JButton     button = new JButton("Select A File");
          contentPane.setLayout(new FlowLayout());
          contentPane.add(button);          
          chooser.setAccessory(previewPanel);
          chooser.addPropertyChangeListener(
                                             new PropertyChangeListener() {
               public void propertyChange(PropertyChangeEvent e) {
                    if(e.getPropertyName().equals(
                         JFileChooser.SELECTED_FILE_CHANGED_PROPERTY))
                         previewer.update((File)e.getNewValue());
          button.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    chooser.showOpenDialog(null);
     public static void main(String a[]) {
          JFrame f = new Test2();
          f.setBounds(300, 300, 300, 75);
          f.setVisible(true);
          f.setDefaultCloseOperation(
                                        WindowConstants.DISPOSE_ON_CLOSE);
          f.addWindowListener(new WindowAdapter() {
               public void windowClosed(WindowEvent e) {
                    System.exit(0);
class TextPreviewer extends JComponent {
     private ImageIcon icon;
     private JTextArea textArea = new JTextArea();
     public TextPreviewer() {
          setBorder(BorderFactory.createEtchedBorder());
          setLayout(new BorderLayout());
          add(new JScrollPane(textArea), BorderLayout.CENTER);
     public void update(File file) {
          textArea.setText(contentsOfFile(file));
          if(isShowing()) {
               textArea.revalidate();
     static String contentsOfFile(File file) {
          String s = new String();
          char[] buff = new char[50000];
          InputStream is;
          InputStreamReader reader;
          URL url;
          try {
               reader = new FileReader(file);
               int nch;
               while ((
                    nch = reader.read(buff, 0, buff.length)) != -1) {
                    s = s + new String(buff, 0, nch);
          catch (java.io.IOException ex) {
               s = "Could not load file";
          return s;

If you need to use a JFileChooser to select a folder, not a file, use:
JFileChooser jf = new JFileChooser();
jf.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Now, your file chooser is a directory chooser....

Similar Messages

  • How to make Tool Strip have a glass effect?

    How to make Tool Strip have a glass effect? Please Help Me As Fast As Possible . Thx .
    Note : Please write as details as Possible because I am new to vb.

    Another possibility extending the Aero Glass effect.
    ToolStrip backcolor has to be transparent.
    Option Strict On
    Imports System.Runtime.InteropServices
    Public Class Form1
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure MARGINS
    Public cxLeftWidth As Integer
    ' width of left border that retains its size
    Public cxRightWidth As Integer
    ' width of right border that retains its size
    Public cyTopHeight As Integer
    ' height of top border that retains its size
    Public cyBottomHeight As Integer
    ' height of bottom border that retains its size
    End Structure
    <DllImport("DwmApi.dll")> _
    Public Shared Function DwmExtendFrameIntoClientArea(hwnd As IntPtr, ByRef pMarInset As MARGINS) As Integer
    End Function
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
    Me.TransparencyKey = Color.Silver
    Me.BackColor = Color.Silver
    Dim BordersWidth As Integer = CInt((Me.Width - Me.ClientRectangle.Width) / 2)
    ToolStrip1.BackColor = Color.Transparent
    Try
    Dim margins As New MARGINS()
    margins.cxLeftWidth = BordersWidth
    margins.cxRightWidth = BordersWidth
    margins.cyTopHeight = ToolStrip1.Height
    margins.cyBottomHeight = BordersWidth
    DwmExtendFrameIntoClientArea(Me.Handle, margins)
    Catch ex As Exception
    End Try
    End Sub
    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
    Me.Refresh()
    End Sub
    Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    Using Brush1 As New SolidBrush(SystemColors.Control)
    e.Graphics.FillRectangle(Brush1, Me.ClientRectangle.Left, Me.ClientRectangle.Top + ToolStrip1.Height, Me.ClientRectangle.Width, Me.ClientRectangle.Height)
    End Using
    End Sub
    End Class
    La vida loca

  • How to make read only field in Task list?

    Hi All,
    How to make read only field in Task list?

    This can be done one of two ways:
    1. Customize the form in Infopath, right click your field and disable the control.
    2. Use JavaScript/jQuery on the page to disable the element.
    Andy Wessendorf SharePoint Developer II | Rackspace [email protected]

  • Slide duration - How to make one slide have a different duration to another slide?

    Slide duration - How to make one slide have a different duration to another slide?
    EG So one slide has 2 seconds, another 4 another 6
    All I can see is how to make all slides have the same duration
    Any help very much appreciated!
    Brian

    Slide durations are not changeable on a slide-by-slide basis.

  • How to make table cell have certain width

    Hi
    i have 3 cells when i write text in any cell it effects the
    width of other cells !!!
    how to make every cell have certain? i mean i want to wrap
    the text not to effect the cell width
    thanks in advance.

    Hi Mac,
    Try this
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
    Transitional//EN">
    <HTML><HEAD><TITLE>Home</TITLE>
    <META http-equiv=Content-Type content="text/html;
    charset=iso-8859-1">
    <style>
    .text-content-green {
    FONT-SIZE: 11px;
    COLOR: #a5a834;
    LINE-HEIGHT: 20px;
    FONT-STYLE: normal;
    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
    TEXT-DECORATION: none;
    .text-content-green:hover {
    FONT-SIZE: 11px;
    COLOR: #AE0B0B;
    LINE-HEIGHT: 20px;
    FONT-STYLE: normal;
    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
    TEXT-DECORATION:underline;
    .margin {
    margin: 1px 1px 1px 1px;
    border-style: solid;
    border-top-width: 1px;
    border-left-width: 1px;
    border-right-width: 1px;
    border-bottom-width: 1px;
    border-color: gainsboro;
    </style
    </HEAD>
    <BODY topmargin="10px" leftmargin="0" rightmargin="0"
    class="body-style">
    <TABLE width="729" border="0" cellpadding="0"
    cellspacing="0" cellsadding="0" align="center" class="margin">
    <TBODY>
    <TR>
    <TD width="125" valign="top" bgcolor="#f0f0c1">
    <table width="125" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td width="25" height="25" align="middle"></td>
    <td width="108" class="text-content-green"><A
    class="text-content-green" href="default.html">LEFT
    NAV</A></td>
    </tr>
    <tr>
    <td colspan="2" align="middle"></td>
    </tr>
    <tr>
    <td width="25" height="25" align="middle"></td>
    <td width="108" class="text-content-green"></td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    </table>
    </TD>
    <TD vAlign=top width=539 bgColor="white" height=471>
    <P class="text-content-green" align=left
    style="padding-left:5px">Lorem ipsum dolor sit amet, consectetur
    adipisicing elit.Duis aute irure dolor in reprehenderit in
    voluptate velit esse cillum .
    </P>
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </BODY>
    </HTML>
    HTH
    Shanthi

  • Why do I only have photos option to choose from for uploading my resume?

    I'm applying for jobs and have Dropbox plus PDF but when it comes to attaching my resume on job sites I only have the option to choose from photos.  Why?!!!!  Why in the heck do I only have this ONE limited option?  I have PDF and Dropbox- how come I can't choose my resume from there to attach my resume on job applications on line? 
    Is there some setting or some kind of control I need to fix?  Any feedback appreciated. Sorry, I'm frustrated!

    There are are certain functions that can only be executed during the "WhilePrintingRecords" pass of the report execution. Any formula that uses one of these functions cannot be summarized.
    Also any formula that is is based on aggregated values cannot be summarized.
    HTH,
    Jason

  • Hi,  I backed up my ipad and iphone on the same computer, will it be shown on the same folder or different? Mine is window 7, try to find the back up file follow the step that apple provided, it shown only iphone instead of ipad. Pls help.

    I backed up my ipad and iphone on the same computer, will it be shown on the same folder or different? Mine is window 7, try to find the back up file follow the step that apple provided, it shown only iphone instead of ipad. Pls help.

    What do you see under Edit > Preferences > Devices?
    tt2

  • I can't email a photo directly from iPhoto.  First, I only have two "themes" to choose from instead of 8, and when prompted to fill in the "to" and "from", the "from" box has "MobileMe" already in it, and I can't get rid of or change it. I have OSXLion

    I can't email a photo directly from iPhoto.  First, I only have two "themes" to choose from instead of 8, and when prompted to fill in the "to" and "from", the "from" box has "MobileMe" already in it, and I can't get rid of or change it. I have OSXLion

    I understand, as that was the place I would change it before 8.3 but now that option of Mail Days to Sync is not available?  Any idea why that would be?

  • How to create Short Lived process?..can neone pls help...

    How to create Short Lived process?..can neone pls help...

    Hi,
    Login into workbench. Click on Help->Workbench start page.
    Lot of helps are there you can go through them. They will be helpful.
    But it seems you are new to livecycle, so it will difficult to start through help. Either you can take help of any of your team member who is expert in livecycle or some training you should attend.
    Thanks

  • How to make the filter panel non-folder specific in Bridge CS6

    It seems that the filter panel is folder specific. You click on a folder and only some filters pop up depending on what folder you are looking at and what info is in the photos (I don't know if this refers to tags or not). Assuming I am right. This is my problem. I go to my main folder where all other folders and subfolder with photos within them are placed. I want to look at my "Ratings" 5 starts, 4 stars and so forth. In other words I am looking for (searching for), in this case, all those photos I have labeled with 5 stars. But no such tab/filter exists in my main folder. Why? How do I perform such a task(look for all 5-star photos I have--and also zero stars, those yet to be labelled)?
    OS: WIndows 7 Home Premium 64bit
    Thank you

    The filter panel is a shortcut for the content panel and it only effects the content of that window. So if you have a folder it will only see this as a folder and not with its content. (a Stack behaves about the same, being different in only counting the first file in the filter panel criteria but not what is in the stack itself)
    You have a view work arounds, first is use menu view / show items from subfolders (this can take some time especially if you have not used caching before on this content) and this builds visible thumbs for all content and that can be used for filtering.
    Or use the find command (Edit / find) and inhere specify the source and fill in the criteria include subfolders and this will give you the correct result.
    When you create a smart collection the find command also pops up given you the same opportunity to get the results in a collection, but since a collection is only a bunch of aliases referring to the originals you might be a bit careful with editing and deleting.

  • Boris 3D: How to make the alphabets have thickness ?

    QUESTION 1:
    In Boris 3D, how to make the alphabets to have thickness ?
    QUESTION 2:
    I have done some opening title animation using Boris 3D. But I think I will use the same animation opening title in other projects file. How do I copy this animation of the Boris 3D title in from one project to the other project ?
    Thanks

    In Boris 3D, how to make the alphabets to have thickness ?
    I believe the only way to do what you want would be to either choose a thicker font or push up the font size (which would also affect the font height).
    How do I copy this animation of the Boris 3D title in from one project to the other project ?
    The easiest way, would either be to:
    a) if it is all one clip, simply copy it from the timeline of the first project, then paste it into the timeline or browser of the second project
    b) if it is more than one clip, export only that part of the sequence as described here to a Quicktime Movie:
    http://fcpbook.com/Misc8.html
    And then import that Quicktime Movie into your new project.

  • How to make an image of a folder.

    I want to make back up my applications folder cause I have alot of stuff that if I were to lose it I wouldn't even know what to redownload or get from where ever else, when I try to transfer the folder to my external hd it takes forever because it wants to scan everything in the package contents of every app. so I want to make an image so I can transfer real quick. and I can just restore everything a little easier. is there anything I can use to do this that came in OS X or any freeware I could get?

    It would actually be easier to make an archive of the folder. Just control-click the folder and select "Creat Archive of '<name of folder>'" But, if you still want to make an image, go do Disk Utility, and then click "New Image" at the top of the window. Next, you'll have to name the image, and select the size (everything other opttion can stay as it is). After you create the image, it will open and you'll have to drag your folders contents (or the folder) into the open image, then eject it. After that, your image is finished.
    Zeb

  • How to make servlet work in my folder

    I created a servlet called FirstServlet.java (no package it belongs to) and used Tomcat-4.1.7.
    If the servlet is put in "jakarta-tomcat-4.1.7/webapps/examples/WEB-INF/classes", it can be run at URL: localhost:8080/examples/servlet/FirstServlet. Now I created a folder in "webapps", called "test". My question is how to make FirstServlet.java work in "jakarta-tomcat-4.1.7/webapps/test/" or its subfolder?
    I tried putting the servlet class in "jakarta-tomcat-4.1.7/webapps/test/WEB-INF/classes/" and running it at http://localhost:8080/test/servlet/FirstServlet, but it failed with msg saying "requested resource is not available".
    Any advice is appreciated.

    You need to set 'Context Path' for your 'test' (application) in conf\server.xml file.
    It will be something like this, add these lines in that file and restart Tomcat.
    <Context path="/test"
    docBase="webapps/test"
    crossContext="true"
    debug="0"
    reloadable="true"
    trusted="false" >
    </Context>
    Sudha

  • HT200131 how to make sure only my laptop can connect to my apple tv?

    I don't want to see my flatmate apple tv under "connect"
    how to make sure I don't click on his tv accidentally and he won't be able to connect mine?
    thank you!

    Hey J-Justin,
    Great question! You can name your Apple TV to differentiate it from others in the AirPlay list:
    Apple TV: Change the name of your Apple TV - Apple Support
    http://support.apple.com/en-us/HT200028
    Furthermore, you can setup an onscreen code or password to restrict access for AirPlay. The password method sounds like the best option for your setup:
    Apple TV (2nd and 3rd generation): Understanding AirPlay settings - Apple Support
    http://support.apple.com/en-us/HT202618
    Set a password
    Go to Settings > AirPlay > Security > Password > [set password]. You can use this setting to require a password for AirPlay-enabled devices to connect using AirPlay on the Apple TV. Use this setting if your device will need permanent access and you only want to enter the password once.
    Thanks,
    Matt M.

  • ALV - how to make selectable only some rows on an ALV?

    Hi my problem is:
    I have an ALV GRID as output of a report.
    I have to make selectable only few rows based on the contents of a field (showed in a column in the ALV).
    Is it possible?
    Best Regards, Vincenzo

    I did understand, but as i told you there is nothing like that, neither an option nor an event to capture.
    Here is the documentation: http://help.sap.com/saphelp_erp2005vp/helpdata/EN/bf/3bd1369f2d280ee10000009b38f889/frameset.htm
    Read it and choose what you need and what is in existance.

Maybe you are looking for