Closed MatthiasGi closed 13 years ago
Github is no JIRA. I assumed it would post my comment when I closed it. Instead it looked like I posted it but it actually ate it. Bad UI... Bad UI!
Anyway, the issue is the timing of setting the look and feel. You need to set it prior to creating any JComponent, and certianly not inside the constructor for a JFrame. The super constructor creates some features of JFrame that are ultimately dependent on the look and feel, and changing things mid-flight is not something the code is expecting to happen.
By moving the look and feel configuration to the main method I was able to make things work. Here's what worked for me.
package de.gianfelice.debarim.gui;
import java.awt.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel;
public class SampleApp extends JFrame {
public SampleApp() {
super("Sample app");
try {
this.setLayout(new FlowLayout());
this.add(new JButton("button"));
this.add(new JCheckBox("check"));
this.add(new JLabel("label"));
this.setSize(new Dimension(250, 80));
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(new SubstanceGraphiteLookAndFeel());
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(SampleApp.class.getName()).log(Level.SEVERE, null, ex);
}
JFrame.setDefaultLookAndFeelDecorated(true);
SampleApp s = new SampleApp();
s.setVisible(true);
}
});
}
}
FWIW, I was able to run the original code with no errors under Java 1.6.0_20.
First: Thanks to you for trying to help me, but unfortunately this does not work for me:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at org.pushingpixels.substance.internal.utils.SubstanceColorUtilities.getDefaultBackgroundColor(SubstanceColorUtilities.java:830) at org.pushingpixels.substance.internal.utils.SubstanceColorUtilities.getBackgroundFillColor(SubstanceColorUtilities.java:733) at org.pushingpixels.substance.internal.ui.SubstancePanelUI.__org__pushingpixels__substance__internal__ui__SubstancePanelUI__installDefaults(SubstancePanelUI.java:73) at org.pushingpixels.substance.internal.ui.SubstancePanelUI.installDefaults(SubstancePanelUI.java) at javax.swing.plaf.basic.BasicPanelUI.installUI(BasicPanelUI.java:39) at org.pushingpixels.substance.internal.ui.SubstancePanelUI.__org__pushingpixels__substance__internal__ui__SubstancePanelUI__installUI(SubstancePanelUI.java) at org.pushingpixels.substance.internal.ui.SubstancePanelUI.installUI(SubstancePanelUI.java) at javax.swing.JComponent.setUI(JComponent.java:662) at javax.swing.JPanel.setUI(JPanel.java:136) at javax.swing.JPanel.updateUI(JPanel.java:109) at javax.swing.JPanel.(JPanel.java:69) at javax.swing.JPanel. (JPanel.java:92) at javax.swing.JPanel. (JPanel.java:100) at javax.swing.JRootPane.createGlassPane(JRootPane.java:528) at javax.swing.JRootPane. (JRootPane.java:348) at javax.swing.JFrame.createRootPane(JFrame.java:255) at javax.swing.JFrame.frameInit(JFrame.java:236) at javax.swing.JFrame. (JFrame.java:203) at de.gianfelice.debarim.gui.SampleApp. (SampleApp.java:12) at de.gianfelice.debarim.gui.SampleApp$1.run(SampleApp.java:38) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641) at java.awt.EventQueue.access$000(EventQueue.java:84) at java.awt.EventQueue$1.run(EventQueue.java:602) at java.awt.EventQueue$1.run(EventQueue.java:600) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:611) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
I just copied and pasted your code. I downloaded the jars from your website, did I something wrong?
Again thank you very much and greetings from Germany, Matthias
Matthias, can you provide the links where you downloaded the jars from?
Hello lunaflare,
of course I can! Here is it: http://shemnon.com/speling/2011/04/insubstantial-62-release.html
If I understood everything right, it is the private homepage of shemnon. On my Windows 7 here I don't have git, but on my GNU/Linux I do. But I don't think, that it would change anything to download them there...
Greetings from Germany and I'm really sorry for my poor English, Matthias
Edit: Well, also it would be really great, if anyone could provide the sourcecode of the last two examples of the metioned page?
Hmm, I still wasn't able to produce your issue using those libraries. Here's what I did:
javac -classpath substance-6.2.jar -d bin SampleApp.java
java -classpath substance-6.2.jar;trident-6.2.jar;bin de.gianfelice.debarim.gui.SampleApp
I'm running 32-bit Java 1.6.0_20 on the command line of Windows 7 x64.
The Flamingo example code is at https://github.com/Insubstantial/insubstantial/blob/master/substance-flamingo/src/test/java/test/substance/ribbon/NewCheckRibbon.java
I could find the error: In my IDE, I also checked the library substance-swingx. I had another error in this project and included everything, what could work. That error could be solved.
Well, and without this library, everything works just well. Sorry for my dumb issuereport!
Thanks to all for the helping and sorry again for bothering you with this...
Greetings from Germany, Matthias
P.S.: And thanks for the link @lunaflare!
Edit: Well, after a bit testing, I must assume, that the windows are not compatible to some Windows 7 Features: Aero Snap (Moving them to one side for maximizing and organizing), also some Shortcuts (Win + Up etc) don't work. I will try it on GNOME 3 later, if anyone is intrested. I don't know how important this is.
No worries and glad to help.
I've got this sample-code:
But everytime I try to run this code, I get a NullPointerException:
Everything is running under NetBeans 7.0 and Windows 7 x64. I'm not using Maven to do this.
Maybe I'm only doing something wrong?
If I could provide any further information, please let me know.
Greetings from Germany, Matthias