Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2 mins to create a JFileChooser  (Read 3570 times)
0 Members and 1 Guest are viewing this topic.
Offline MBrenaman

Junior Devvie




Javanaut


« Posted 2004-09-08 10:32:47 »

Yes its me again. I wanted to add save/load feature to the game I'm making and I wanted to use the JFileChooser.

On my system P4 1.6ghz Java VM 1.4.2, it literally takes like 2 minutes to create one new JFileChooser object. So this made the game startup way to slow.

So I went to using the FileDialog class from AWT and the FilenameFilter doesnt actually work on my system even though I made my FilenameFilter class, filled in everything right and added it the FileDialog object.

So, what I want to know is 1. Why does it take so long to create a JFileChooser 2. Is there some good fix's/alternatives for making a load/save dialog box.

Thnx for your time.

-Mathew Brenaman
Offline DrBizzar0

Junior Devvie




Raj raj!


« Reply #1 - Posted 2004-09-08 11:48:12 »

Thats weird, I've never had any problems with JFileChooser, opens in less then a second in both Linux and Windows on a similar machine. Guess you'll have to post som source code for anybody to be able to help.  But on the other hand it only takes two lines of code to create the file chooser

1  
2  
3  
final JFileChooser fc = new JFileChooser();

int returnVal = fc.showOpenDialog(aComponent);


So there's not much you can have done wrong Smiley

You haven't accidentally put the creation in some loop or anything like that?
Offline MBrenaman

Junior Devvie




Javanaut


« Reply #2 - Posted 2004-09-08 15:33:47 »

Nope creation's not in a loop. I'm sure of that. I checked and rechecked, ran the -Xprof and -Xaprof to see if anything was going wrong then, I tried the FileChooserDemo from Sun and that does the same exact thing on my system  :-/.  

Also i didnt include that I use WinXp.

I would post the code but its the same as what you have stated. However, here is the game's profiled output from it starts to when it makes the JFileChooser to when it hits the title screen.


Flat profile of 1.94 secs (179 total ticks): AWT-Shutdown

 Interpreted + native   Method
16.7%     0  +     1    java.lang.Object.wait
16.7%     0  +     1    Total interpreted

 Thread-local ticks:
96.6%   173             Blocked (of total)
83.3%     5             Class loader


Flat profile of 1.08 secs (100 total ticks): AWT-EventQueue-0

 Thread-local ticks:
99.0%    99             Blocked (of total)
100.0%     1             Compilation


Flat profile of 88.12 secs (8174 total ticks): AWT-Windows

 Interpreted + native   Method
100.0%     0  +  8173    sun.awt.windows.WToolkit.eventLoop
 0.0%     0  +     1    sun.awt.windows.WToolkit.init
100.0%     0  +  8174    Total interpreted


Flat profile of 0.11 secs (10 total ticks): Thread-0

 Interpreted + native   Method
100.0%     0  +    10    sun.awt.windows.WToolkit.shutdown
100.0%     0  +    10    Total interpreted


Flat profile of 7.63 secs (685 total ticks): AWT-EventQueue-0

 Interpreted + native   Method
 1.5%     0  +     2    sun.awt.windows.WInputMethod.setConversionStatus
 0.7%     0  +     1    sun.awt.im.InputContext.class$
 0.7%     0  +     1    sun.awt.im.CompositionAreaHandler.<clinit>
 0.7%     0  +     1    javax.swing.LayoutFocusTraversalPolicy.accept
 0.7%     0  +     1    sun.awt.windows.Win32OffScreenSurfaceData.initSurface
 4.4%     0  +     6    Total interpreted

 Thread-local ticks:
80.1%   549             Blocked (of total)
 1.5%     2             Class loader
94.1%   128             Compilation


Flat profile of 7.63 secs (686 total ticks): AWT-Shutdown

 Interpreted + native   Method
100.0%     0  +     1    java.lang.Object.wait
100.0%     0  +     1    Total interpreted

 Thread-local ticks:
99.9%   685             Blocked (of total)


Flat profile of 89.42 secs (8293 total ticks): main

 Interpreted + native   Method
76.2%     0  +  6309    sun.awt.shell.Win32ShellFolder2.getAttributes0
 4.9%     0  +   404    sun.awt.font.NativeFontWrapper.registerFonts
 3.9%     0  +   322    sun.awt.shell.Win32ShellFolder2.getDisplayNameOf
 2.8%     0  +   236    sun.awt.shell.Win32ShellFolder2.getNextChild
 1.9%     0  +   158    sun.java2d.loops.Blit.Blit
 1.0%     0  +    85    java.io.FileInputStream.open
 0.8%     0  +    64    sun.awt.shell.Win32ShellFolder2.getEnumObjects
 0.6%     0  +    50    sun.awt.windows.WToolkit.sync
 0.5%     0  +    42    java.io.WinNTFileSystem.getBooleanAttributes
 0.5%     0  +    40    java.lang.ClassLoader$NativeLibrary.load
 0.4%     0  +    35    java.io.RandomAccessFile.setLength
 0.3%     0  +    27    java.io.FileInputStream.readBytes
 0.3%     0  +    27    sun.awt.windows.Win32BlitLoops.Blit
 0.3%     0  +    23    sun.awt.shell.Win32ShellFolder2.initIDs
 0.2%     0  +    15    sun.awt.windows.WWindowPeer._setTitle
 0.2%     0  +    14    sun.awt.font.NativeFontWrapper.getFontMetrics
 0.1%     0  +    12    sun.awt.windows.Win32SurfaceData.initDDraw
 0.1%     0  +    12    sun.awt.windows.WDesktopProperties.getWindowsParameters

 0.1%     0  +    10    sun.awt.font.GlyphList.setupStringData
 0.1%     0  +    10    java.io.RandomAccessFile.close0
 0.1%     0  +     9    sun.awt.Win32GraphicsEnvironment.registerFontWithPlatfo
rm
 0.1%     0  +     5    java.io.WinNTFileSystem.canonicalize0
 0.1%     0  +     5    java.io.WinNTFileSystem.createFileExclusively
 0.0%     0  +     4    java.io.WinNTFileSystem.canonicalizeWithPrefix0
 0.0%     0  +     4    java.io.WinNTFileSystem.checkAccess
97.2%    41  +  8008    Total interpreted (including elided)

    Compiled + native   Method
 0.1%    10  +     0    com.sun.imageio.plugins.gif.GIFImageReader.read
 0.0%     2  +     0    com.sun.imageio.plugins.gif.GIFImageReader.getCode
 0.0%     2  +     0    com.sun.imageio.plugins.gif.GIFImageReader.outputPixels

 0.0%     1  +     0    java.lang.String.indexOf
 0.0%     0  +     1    java.lang.StringBuffer.toString
 0.0%     1  +     0    java.io.StreamTokenizer.read
 0.0%     0  +     1    java.lang.String.getChars
 0.0%     1  +     0    java.nio.Buffer.<init>
 0.0%     0  +     1    TimeSmoothie.getAverage
 0.0%     1  +     0    java.util.Arrays.binarySearch
 0.0%     0  +     1    java.io.BufferedInputStream.read1
 0.0%     0  +     1    java.io.BufferedInputStream.read
 0.0%     1  +     0    vtable chunks
 0.3%    19  +     5    Total compiled

        Stub + native   Method
 0.4%     0  +    34    java.io.RandomAccessFile.setLength
 0.1%     0  +    11    java.lang.StrictMath.pow
 0.1%     0  +     6    java.io.RandomAccessFile.writeBytes
 0.1%     0  +     6    sun.awt.shell.Win32ShellFolder2.getAttributes0
 0.0%     0  +     1    java.io.RandomAccessFile.seek
 0.0%     0  +     1    java.lang.StrictMath.floor
 0.0%     0  +     1    java.io.RandomAccessFile.length
 0.7%     0  +    60    Total stub

 Thread-local ticks:
 0.1%     9             Blocked (of total)
 1.7%   144             Class loader
 0.0%     2             Interpreter
 0.0%     3             Compilation
 0.0%     2             Unknown: no last frame


Global summary of 89.42 seconds:
100.0%  8320             Received ticks
 0.3%    26             Received GC ticks
 0.3%    21             Compilation
 1.8%   151             Class loader
 0.0%     2             Interpreter
 0.0%     2             Unknown code


Maybe that has some clue, not sure what sun.awt.shell.Win32ShellFolder2.getAttributes0 is. Maybe someone can see something abnormal with this?

EDIT: I tried installing and running it under JRE 1.4.2_05, no difference for either my app or FileChooserDemo from Sun.

-Mathew Brenaman
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mark Thornton

Senior Devvie





« Reply #3 - Posted 2004-09-08 17:32:59 »

Even Windows Explorer sometimes takes a long time to enumerate some directories. Try setting the initial directory to some innocuous location that has no special content (just ordinary .txt files for example). Ideally FileChooser would fill its file list in the background ...
Offline MBrenaman

Junior Devvie




Javanaut


« Reply #4 - Posted 2004-09-08 19:11:15 »

Well, I tried to set regular old FileChooser's FilenameFilter right after its creation in the apps startup code. That still doesnt work  Roll Eyes

Second, the delay is the actual creation statment JFileChooser jfc = new JFileChooser(); in the apps startup code. It causes the whole app to hang for way to long.  :-/

EDIT: O, sorry, I tried setting JFileChooser's initial directory to something on my computer with nothing in it and it still hangs for to long.

-Mathew Brenaman
Offline DrBizzar0

Junior Devvie




Raj raj!


« Reply #5 - Posted 2004-09-09 06:47:37 »

I think you should test the application on another computer, to see if the problem can be reproduced there. If Suns example code also runs slow it's probably some issue with your computer.

I didn't find any relevant bugs in the bug database, the closest was this one http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5084718. But it seems to only affect earlier builds of 5.0 beta. In the bug repport the slow down occurs when you have a slow network connection.
Offline MBrenaman

Junior Devvie




Javanaut


« Reply #6 - Posted 2004-09-09 07:33:37 »

I got it resolved  Grin!

For WinXP users with this problem check out http://forum.java.sun.com/thread.jsp?forum=57&thread=437304&start=30&range=15&hilite=false&q=>

I just turned off WinXP's default file association with zips and bam, works like a charm.

To turn it off if you have the problem,

regsvr32 /u %windir%\system32\zipfldr.dll


To turn it back on if you need it, (I'm getting winzip, screw XP!)

regsvr32 %windir%\system32\zipfldr.dll

-Mathew Brenaman
Offline dranonymous

Junior Devvie




Hoping to become a Java Titan someday!


« Reply #7 - Posted 2004-09-10 11:27:31 »

Something which sounds similiar is a problem I had when opening a color chooser dialog.  On my home computer with XP its works fine.  On my work XP computer, it took forever to open up.

Very weird.

Dr. A>
Offline Backmask

Junior Devvie




586: The average IQ needed to understand a PC


« Reply #8 - Posted 2004-09-10 13:48:42 »

In WinXp when you open any form of explorer, open/load/save dialog or similiar, windows will always start to examine the files in the current directory and for certain file types (mp3, avi, zip ...) extra information is extracted from the file. This is done by a separate thread but for some reason it hangs the explore window when examine a file. But during the time for switching from one file to another the explore window can be used.

For mp3, length, artist, album, are extracted from the ID2/3 tag.
For Avi the total length of the movie are extracted.
For zip the total amount of files are extracted.

These extraction of extra data takes a long time if the file are large, for example a 700mb avi file takes for ever and can sometimes lock the computer until the length has been extracted. For zip files as mention abow the time to examine the a large compressed file can take up to some minutes. At work we compress all our configuration files (xml) for our J2EE platform and it contains about 10000 files (40mb compressed). When trying to explore in the same directory as this zip-file windows hangs forever or so it feels.

So use the abow to disable the zip examine. There is another .dll for the avi that can be uninstalled to but I don't remember the name of it.

The MS designer that thought a computer could examine large files in a flash should be shoot.

Offline MBrenaman

Junior Devvie




Javanaut


« Reply #9 - Posted 2004-09-11 03:09:56 »

Quote

The MS designer that thought a computer could examine large files in a flash should be shoot.


Amen  Grin

-Mathew Brenaman
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #10 - Posted 2004-09-13 01:59:13 »

Sounds more like they need to learn how to do multi-threaded programming.  No surprise that they suck at that though.  They still use "drive letters" and munged 8.3 filenames for heaven's sake!   Soon as the OS moved slightly beyond MS-DOS, I think all the MS programmers became hopelessly lost Smiley.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (60 views)
2014-12-09 22:41:13

BurntPizza (95 views)
2014-12-08 04:46:31

JscottyBieshaar (55 views)
2014-12-05 12:39:02

SHC (71 views)
2014-12-03 16:27:13

CopyableCougar4 (73 views)
2014-11-29 21:32:03

toopeicgaming1999 (133 views)
2014-11-26 15:22:04

toopeicgaming1999 (124 views)
2014-11-26 15:20:36

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!