Problema com o substance Look and Feel

11 respostas
souarte

olá. queria colocar um LAF diferente na aplicação desktop . o meu método main ficou assim:

public static void main(String args[]) {
		final String[] args2 = args;

		JFrame.setDefaultLookAndFeelDecorated(true);
		try {
			UIManager.setLookAndFeel(new SubstanceBusinessLookAndFeel());
			SubstanceLookAndFeel.setSkin(new CremeCoffeeSkin());
		} catch (Exception e) {
			System.out.println("Substance Raven Graphite failed to initialize");
			e.printStackTrace();
		}

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				String[] cvwinfo;

				cvwinfo = parseArgs(args2);
				JCVWApplic app = new JCVWApplic();
				app.init(cvwinfo[0], cvwinfo[2]); //server.cvw, fontpref

				app.start(cvwinfo);
			}
		});
	}
ele xega a abrir a tela, mas depois dá as seguintes exceções:
org.jvnet.substance.api.UiThreadingViolationException: Component creation must be done on Event Dispatch Thread
	at org.jvnet.substance.utils.SubstanceCoreUtilities.testComponentCreationThreadingViolation(SubstanceCoreUtilities.java:2312)
	at org.jvnet.substance.SubstanceMenuUI.createUI(SubstanceMenuUI.java:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at sun.reflect.misc.Trampoline.invoke(Unknown Source)
	at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
	at javax.swing.UIDefaults.getUI(Unknown Source)
	at javax.swing.UIManager.getUI(Unknown Source)
	at javax.swing.JMenu.updateUI(Unknown Source)
	at javax.swing.JMenuItem.init(Unknown Source)
	at javax.swing.JMenuItem.<init>(Unknown Source)
	at javax.swing.JMenuItem.<init>(Unknown Source)
	at javax.swing.JMenu.<init>(Unknown Source)
	at org.mitre.cvw.CVWCoordinator.buildMenuBar(CVWCoordinator.java:1179)
	at org.mitre.cvw.CVWCoordinator.initUserID(CVWCoordinator.java:3473)
	at org.mitre.cvw.CVWServerComm.processMCP(CVWServerComm.java:1217)
	at org.mitre.cvw.CVWServerComm.receiveLine(CVWServerComm.java:438)
	at org.mitre.cvw.NetThread.run(NetThread.java:58)
UIDefaults.getUI() failed: createUI() failed for javax.swing.JMenu[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=null,paintBorder=false,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=New] java.lang.reflect.InvocationTargetException
java.lang.Error.

11 Respostas

RobsonFagundes

souarte da uma olhada neste post
ve se te ajuda
http://www.guj.com.br/posts/list/65370.java#344730
t+

souarte

cara, infelizmente nao ajudou.
ele começa a dar erros quando eu crio um JMenuItem. e a partir daí tudo dá excessao também.
acredito que a solução pode ser encontrada lendo essa excesão:
org.jvnet.substance.api.UiThreadingViolationException: Component creation must be done on Event Dispatch Thread

mas infelizmente eu nao sei o q fazer pra dar certo.

T

Esse tipo de coisa (criar coisas na Event Dispatch Thread) normalmente se resolve com SwingUtilities, método invokeLater:

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/SwingUtilities.html

invokeLater

souarte

é eu coloquei o código que dava erro dentro das seguintes linhas:

SwingUtilities.invokeLater(new Runnable() { public void run() { //o código que dava erro. } });

e ficou ok, poreém outras partes da aplicação também deram o mesmo erro.
então, faço o mesmo com as outras partes que derem erro? ou isso pode causar algum efeito colateral no código e é melhor eu desistir de usar esse LAF?

G

Tive esse mesmo problema com o Substance e para resolver basta você colocar a inicialização da parte GUI do seu programa dentro do SwingUtilities

public static void main(String[] args) {
	String LAFName = "org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel";

	try {
		UIManager.setLookAndFeel(LAFName);	
	} catch (Exception e) {
		System.out.println("Substance " + LAFName + " failed to initialize");
	}
	SwingUtilities.invokeLater(new Runnable() {
		public void run() {
			//inicialização da parte GUI do seu programa
		}
	});
}
souarte
eu já havia feito isso, mas infelizmente continuou acontecendo o mesmo problema.
public static void main(String args[]) {  
            final String[] args2 = args;  
      
            JFrame.setDefaultLookAndFeelDecorated(true);  
            try {  
                UIManager.setLookAndFeel(new SubstanceBusinessLookAndFeel());  
                SubstanceLookAndFeel.setSkin(new CremeCoffeeSkin());  
            } catch (Exception e) {  
                System.out.println("Substance Raven Graphite failed to initialize");  
               e.printStackTrace();  
           }  
     
           SwingUtilities.invokeLater(new Runnable() {  
               public void run() {  
                   String[] cvwinfo;  
     
                   cvwinfo = parseArgs(args2);  
                   JCVWApplic app = new JCVWApplic();  
                   app.init(cvwinfo[0], cvwinfo[2]);
     
                   app.start(cvwinfo);  
               }  
           });  
       }

como você vê o método app.init() é o método que inicializa a GUI.

T

Acho que você tem de executar UIManager.setLookAndFeel antes de executar JFrame.setDefaultLookAndFeelDecorated.

Vinny

Bom o meu qdo eu rodo da os seguintes erros:

java.lang.ClassNotFoundException: org.jvnet.substance.SubstanceRavenLookAndFeel

at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)

at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:242)

at javax.swing.SwingUtilities.loadSystemClass(SwingUtilities.java:1783)

at javax.swing.UIManager.setLookAndFeel(UIManager.java:480)

at biblioteca.Biblioteca.main(Biblioteca.java:35)

Process exited with exit code 0.

O Programa roda mas nao define o look and feel

minha chamada do look and feel ta assim

try
    {
          JFrame.setDefaultLookAndFeelDecorated(true);
          JDialog.setDefaultLookAndFeelDecorated(true);
          UIManager.setLookAndFeel("org.jvnet.substance.SubstanceRavenLookAndFeel");
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
souarte

bom eu nao sou a melhor pessoa pra responder, hehe, mas acho que é porque o jar do Substance nao está no classpath. ou tou errado? :slight_smile:

Vinny

para adicionar o substance na classpath

para adicionar eu fiz assim ve se eu to certo:

TOOLS-PROJECT PROPERTIES…-LIBRARIES-ADD JAR/DIRECTORY

dovalegabriel

A dica do gcoutinho funcionou perfeitamente por aqui! valeu meu brother!

Criado 19 de setembro de 2008
Ultima resposta 1 de jan. de 2009
Respostas 11
Participantes 6