Dies ist eine statische Kopie unseres alten Forums. Es sind keine Interaktionen möglich.
This is a static copy of our old forum. Interactions are not possible.

double

Trainee

  • "double" is male
  • "double" started this thread

Posts: 43

Date of registration: May 12th 2004

Location: Barsinghausen

1

Wednesday, October 27th 2004, 11:23am

JFileChooser vs. Windows Look&Feel (JDK 1.4.2)

Hi!

Der JFileChooser lässt sich (bisher) nicht von mir überreden auch
mit einem Windows Look&Feel zuarbeiten. Wohlgemerkt, ein anderes
L&F lässt sich benutzen, ist jedoch nicht erwünscht.

Vielleicht findet jemand einen WORKAROUND, damit dieses Programm auch im Windows L&F und nicht nur im Metall L&F läuft...
Schon mal vielen Dank!!!

Hier nun ein minimales & kompilierbares Beispiel
(mein System: JDK 1.4.2_04, Windows XP)


<----------------------- FileChooserDemo.java ---------------------->

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * Demonstriert: FileChooser + Windows Look&Feel = Exceptions
 **/

public class FileChooserDemo extends JPanel
                              implements ActionListener {
    private JFileChooser fc;

    public FileChooserDemo () {
        super();
        JButton openButton = new JButton("Datei öffnen...");
        openButton.addActionListener(this);
        add(openButton);
    }

    public void actionPerformed(ActionEvent e) {
        fc = new JFileChooser();
        System.out.println("<<---- Diese Zeile wird im Windows L&F NIE erreicht ---->>");
        int returnVal = fc.showDialog(FileChooserDemo.this,"Datei Öffnen...");
      
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            System.out.println("ausgewählte Datei: " + file.getName());
        }
        fc.setSelectedFile(null);
    }

    /**
     * GUI erstellen.
     */
    private static void createGUI() {
        JFrame frame = new JFrame("FileChooserDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JComponent newContentPane = new FileChooserDemo();
        newContentPane.setOpaque(true);
        frame.setContentPane(newContentPane);
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
      String laf = UIManager.getSystemLookAndFeelClassName();
      if(laf!=null) {
      try {
        System.out.println(laf);
        UIManager.setLookAndFeel(laf);
      }
      catch(Exception e) {
         e.printStackTrace(); }
      }
      createGUI();
    }
}


<----------------------- FileChooserDemo.java ---------------------->

This post has been edited 4 times, last edit by "double" (Oct 27th 2004, 3:54pm)


PhilRM

Gründer

  • "PhilRM" is male

Posts: 867

Date of registration: Dec 9th 2001

Location: Hannover

Occupation: äh... :)

2

Wednesday, October 27th 2004, 2:02pm

Bei mir läuft das Programm einwandfrei unter Win XP und j2sdk1.4.2_05 sowie j2sdk5.0. Poste mal den gesamten Stack Trace.
"Sie haben also einen, äh, einen Master of Bachelor?" (Human Resources, T-Systems, Cebit)

double

Trainee

  • "double" is male
  • "double" started this thread

Posts: 43

Date of registration: May 12th 2004

Location: Barsinghausen

3

Wednesday, October 27th 2004, 3:51pm

@PhilRM: Benutze j2sdk1.4.2_04 unter Win-XP

bekomme dann folgende Fehlermeldungen:

com.sun.java.swing.plaf.windows.WindowsLookAndFeel
java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
at com.sun.java.swing.plaf.windows.WindowsFileChooserUI$ShortCutPanel.<i
nit>(WindowsFileChooserUI.java:622)
at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFo
lder(WindowsFileChooserUI.java:489)
at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponent
s(WindowsFileChooserUI.java:347)
at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserU
I.java:130)
at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(Window
sFileChooserUI.java:176)
at javax.swing.JComponent.setUI(JComponent.java:449)
at javax.swing.JFileChooser.updateUI(JFileChooser.java:1701)
at javax.swing.JFileChooser.setup(JFileChooser.java:345)
at javax.swing.JFileChooser.<init>(JFileChooser.java:320)
at javax.swing.JFileChooser.<init>(JFileChooser.java:273)
at FileChooserDemo.actionPerformed(FileChooserDemo.java:22)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
86)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

This post has been edited 1 times, last edit by "double" (Oct 27th 2004, 3:52pm)


PhilRM

Gründer

  • "PhilRM" is male

Posts: 867

Date of registration: Dec 9th 2001

Location: Hannover

Occupation: äh... :)

4

Wednesday, October 27th 2004, 5:03pm

Ist vermutlich dieser Bug in 1.4.2:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4711700

Workaround:

Zu Anfang von main() setze folgende Sys-Property:

Source code

1
System.setProperty("swing.disableFileChooserSpeedFix", "true");


In 1.4.2_05 + 5.0 scheint es gefixed zu sein. Ich empfehle, umzusteigen.

-phil
"Sie haben also einen, äh, einen Master of Bachelor?" (Human Resources, T-Systems, Cebit)

double

Trainee

  • "double" is male
  • "double" started this thread

Posts: 43

Date of registration: May 12th 2004

Location: Barsinghausen

5

Thursday, October 28th 2004, 3:50pm

Habe alle alten JDK-Versionen deinstalliert und bin auf 5.0 umgestiegen.
Nach dem Motto "Öfter mal was Neues" bekomme ich nun zur Abwechslung diesen Fehler (mit obigen Code)

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(ImageIcon.java:161)
        at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
        at sun.swing.WindowsPlacesBar.<init>(WindowsPlacesBar.java:82)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.updateUseShellFo
lder(WindowsFileChooserUI.java:509)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installComponent
s(WindowsFileChooserUI.java:203)
        at javax.swing.plaf.basic.BasicFileChooserUI.installUI(BasicFileChooserU
I.java:136)
        at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.installUI(Window
sFileChooserUI.java:140)
        at javax.swing.JComponent.setUI(JComponent.java:650)
        at javax.swing.JFileChooser.updateUI(JFileChooser.java:1755)

(...) und noch 2 Meter so weiter!

Zwar sieht das neue Ocean Look&Feel von 5.0 schon mal besser aus als das Metal L&F, hilft mir aber nicht weiter, da ein Windows L&F verlangt wird.

Jetzt noch jemand ne Idee???

This post has been edited 5 times, last edit by "double" (Oct 28th 2004, 4:34pm)


PhilRM

Gründer

  • "PhilRM" is male

Posts: 867

Date of registration: Dec 9th 2001

Location: Hannover

Occupation: äh... :)

6

Thursday, October 28th 2004, 5:59pm

Hast du denn den oben geposteten Workaround (oder einen der vielen anderen, die im Bug Report gelistet sind) getestet?
"Sie haben also einen, äh, einen Master of Bachelor?" (Human Resources, T-Systems, Cebit)

double

Trainee

  • "double" is male
  • "double" started this thread

Posts: 43

Date of registration: May 12th 2004

Location: Barsinghausen

7

Saturday, October 30th 2004, 12:35pm

Der erstgenannte Workaround:
--> System.setProperty("swing.disableFileChooserSpeedFix", "true");
funktioniert bei mir leider nicht. ;-(

zu den genannten Workarounds im Bugreport:
Das hin- und herschalten zwischen den L&F Windows und Metal in
einem try-catch Block bis keine Exception mehr auftritt funktioniert zwar,
bremst das Programm jedoch stark aus.

Habe daraufhin die Erzeugung des JFileChooser-Objekts an den Anfang
des Programms gesetzt um die Init. während der Startphase hinter einen Splash-Screen zuverstecken.

Der Splash-Screen brennt sich jedoch schon fast in den Monitor ein,
da die Phase doch ziemlich lang ist. Das geht einem schnell auf die Nerven!

Vielleicht geschehen ja noch Zeichen und Wunder...
(to be continued)

This post has been edited 1 times, last edit by "double" (Oct 30th 2004, 12:39pm)