Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  How to use external L&F with another Java app?  (Read 2356 times)
0 Members and 1 Guest are viewing this topic.
Offline Bombadil

Senior Member





« Posted 2004-03-09 12:43:54 »

Hi, is it possible to use an external L&F with other Java applications?

For example I've got a nice L&F inside a Extralf.jar and now would like to use it with ... Jedit.

Probably it's not possible because Jedit isn't looking for the classes inside that Extralf.jf, even if I put the Jar into the JRE/or JEdit's classpath...

Any hack maybe?


PS: While I like the Metal L&F I hate its fat font for menues and the like. JEdit on the other side offers Metal L&F but uses a normal sized font for the menues, so it looks way better. Can I force a Java app which uses L&F to somehow use the normal font, too?
Offline z.e.r.o

Junior Member




Java games rock!


« Reply #1 - Posted 2004-03-09 14:23:25 »

Unless the app can scan for additiona L&F you can't but as you suggested maybe you can hack the class files to load the new L&F (nver tried that but I guess it can be done).

You can use the setFont method on the menu and set to to a "Dialog" PLAIN font :

1  
myMenu.setFont(new Font("Dialog", Font.PLAIN, 12));


If you plan to apply this font on a lot of components you shoul create it once and use it where is needed or just wait that someone else come out with a better way of doing it Smiley

Matteo Anelli
.brain - http://www.dot-brain.com
Offline z.e.r.o

Junior Member




Java games rock!


« Reply #2 - Posted 2004-03-09 14:38:30 »

Found a better and general method Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public static void setUIFont (javax.swing.plaf.FontUIResource f){
    //
   // sets the default font for all Swing components.
   // ex.
   //  setUIFont (new javax.swing.plaf.FontUIResource("Dialog",Font.PLAIN,12));
   //
   java.util.Enumeration keys = UIManager.getDefaults().keys();
  while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      Object value = UIManager.get (key);
      if (value instanceof javax.swing.plaf.FontUIResource)
        UIManager.put (key, f);
      }
    }    


This method iterates and changes every FontUIResource key provided by the UIManager. A bit too heavy on computation and can really mess up thing if what you want is to change only certain components...

To change just a generic class of controls (much better IMHO) try this:

1  
UIManager.put("Label.font",new Font("Dialog", Font.PLAIN,12));

Matteo Anelli
.brain - http://www.dot-brain.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bombadil

Senior Member





« Reply #3 - Posted 2004-03-09 14:54:46 »

Quote
To change just a generic class of controls (much better IMHO) try this:

1  
UIManager.put("Label.font",new Font("Dialog", Font.PLAIN,12));

Ok thanks, for an own application that's fine.
But in case I would like to change these fat ugly bold font of Metal L&F on most Java apps - except JEdit - I would have to decompile their classes and ... somewhere .. insert your line? :-)
Offline z.e.r.o

Junior Member




Java games rock!


« Reply #4 - Posted 2004-03-09 18:00:07 »

Well, you can't insert directly the line you must know what to do and HOW to do using raw bytecode instructions or maybe decompiling and recompiling the modified code (not so simple).

Matteo Anelli
.brain - http://www.dot-brain.com
Offline z.e.r.o

Junior Member




Java games rock!


« Reply #5 - Posted 2004-03-09 18:00:40 »

And also not so legal  Roll Eyes

Matteo Anelli
.brain - http://www.dot-brain.com
Offline overnhet

Junior Member




Java games rock!


« Reply #6 - Posted 2004-03-09 18:15:46 »

In fact you can specify a default L&F. Any application which does not modify the L&F will use the one you choose. You must create a file named 'swing.properties' in jre/lib directory.

An example :
1  
2  
3  
4  
5  
6  
7  
8  
swing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel
swing.installedlafs=Metal,Motif,Windows
swing.installedlaf.Metal.class=javax.swing.plaf.metal.MetalLookAndFeel
swing.installedlaf.Metal.name=Metal
swing.installedlaf.Motif.class=com.sun.java.swing.plaf.motif.MotifLookAndFeel
swing.installedlaf.Motif.name=CDE/Motif
swing.installedlaf.Windows.class=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
swing.installedlaf.Windows.name=MS Windows


Then run SwingSet2 (demo/jfc dir) and the demo should be using Motif. You can choose any L&F, all you need to know is the name of its "main" class.

However to change JEdit Look And Feel you have to use a plugin (I think).
Offline Bombadil

Senior Member





« Reply #7 - Posted 2004-03-10 04:25:18 »

Very nice, that's what I've been looking for.
Works nice with many Java apps.
JEdit doesn't use it though, like you said.
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #8 - Posted 2004-03-10 06:16:26 »

Hm, with the swing.properties file setup correctly, the available L&F show up in JEdit config:

Utilities -> Global Options... -> jEdit -> Appearence


jEdit keeps its choosen L&F in an on config file ($home/.jedit/properties). So it doesn't react to the default set in swing.properties.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Bombadil

Senior Member





« Reply #9 - Posted 2004-03-10 08:08:55 »

Quote
Hm, with the swing.properties file setup correctly, the available L&F show up in JEdit config:

Utilities -> Global Options... -> jEdit -> Appearence

I've put the L&F.jar into the JRE/lib/ext, added the swing.properties and most of the J2SE demos use it then. In JEdit I don't see the new L&F in its GUI Appearence-Config still, but... if I do alter your mentioned jedit-config.properties and add the L&F class name manually, it works. :-)

Very nice.

One last question: Basically I'd be happy with JEdit's way to use the Metal L&F, because the fonts are normal, not bold like with all other Metal L&F using Java apps. But... why is the font normal in JEdit's Metal L&F and bold with the others?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline overnhet

Junior Member




Java games rock!


« Reply #10 - Posted 2004-03-10 09:55:49 »

Quote

One last question: Basically I'd be happy with JEdit's way to use the Metal L&F, because the fonts are normal, not bold like with all other Metal L&F using Java apps. But... why is the font normal in JEdit's Metal L&F and bold with the others?


A quick search in the JDK source code shown that Metal fonts are hardcoded in javax.swing.plaf.DefaultMetalTheme whereas they should be read from swing.properties. So the only way to change it would be to specify a custom Metal theme using plain fonts.

Using -Dswing.metalTheme you can choose the theme you want to apply without modifying the application. However the only themes supported are Ocean and Steel (both using bold fonts).

Anyway you shouldn't try to mess with L&F developement. I had to do this during a training period and it is probably the worst documented feature of Java. Fortunately Sun's code is well written and easy to understand, but I never thought Sun would apply the old open source saying : "the source is the documentation". ;D

EDIT : I looked in my own "dead code repository" and found something interesting. Run the SwingSet2 demo with -Dswing.plaf.metal.controlFont=arial-plain-12, this should do what you wanted.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #11 - Posted 2004-03-10 10:39:23 »

Quote

Anyway you shouldn't try to mess with L&F developement. I had to do this during a training period and it is probably the worst documented feature of Java. Fortunately Sun's code is well written and easy to understand, but I never thought Sun would apply the old open source saying : "the source is the documentation". ;D


Seconded; I was recently trying to help someone out who wanted to mimic the later RISC-OS patterned-background GUI with java, and went looking for LaF docs. It's almost as if there aren't any :(. There are some J1 presentations etc that give you a few bits of general advice on what classes to extend and what to replace. I assumed there are some real docs *somewhere* although neither of us could find them...

Actually, on that topic: do you know a *simple* way to replace the "ugly grey background" possessed by most swing components... with a background image instead? Swing is still years behind the GUI curve in this area (e.g. look at CSS, which built-in the concept that a background could be a color or an image; apparently Swing only has the setBackground( Color ) method and friends?).

malloc will be first against the wall when the revolution comes...
Offline Bombadil

Senior Member





« Reply #12 - Posted 2004-03-10 11:55:37 »

Quote

EDIT : I looked in my own "dead code repository" and found something interesting. Run the SwingSet2 demo with
-Dswing.plaf.metal.controlFont=arial-plain-12, this should do what you wanted.

Yes indeed, this is what I've been looking for! Many thanks. Finally I can make all those Metal L&F apps using a normal font, with just a small -D switch when calling Java, that's great.

So I guess JEdit is setting this controlFont property, too?
Offline overnhet

Junior Member




Java games rock!


« Reply #13 - Posted 2004-03-10 12:57:21 »

Quote

So I guess JEdit is setting this controlFont property, too?


I don't know. In fact the version I use (4.2pre9) has bold fonts but IMO they look nice with Ocean (whereas they were ugly with the old Metal L&F).

Quote

Seconded; I was recently trying to help someone out who wanted to mimic the later RISC-OS patterned-background GUI with java, and went looking for LaF docs. It's almost as if there aren't any :(. There are some J1 presentations etc that give you a few bits of general advice on what classes to extend and what to replace. I assumed there are some real docs *somewhere* although neither of us could find them...

I doubt there are. Each time I had to mess with LAF stuff, I googled everywhere but found nothing. Even the L&F Guidelines book on java.sun.com is disappointing. In the end I unzipped the source code shipped with JDK and spent countless days trying to find out how it works. People who wrote custom L&F must have spent a lot of time on it.

Quote

Actually, on that topic: do you know a *simple* way to replace the "ugly grey background" possessed by most swing components... with a background image instead? Swing is still years behind the GUI curve in this area (e.g. look at CSS, which built-in the concept that a background could be a color or an image; apparently Swing only has the setBackground( Color ) method and friends?).

Never had to do that. However JEdit has a background plugin which does it. Since the source are available you could look in it.

See : http://sourceforge.net/project/showfiles.php?group_id=64089&package_id=67140
Offline Bombadil

Senior Member





« Reply #14 - Posted 2004-03-10 13:09:18 »

Quote

In fact the version I use (4.2pre9) has bold fonts but IMO they look nice with Ocean (whereas they were ugly with the old Metal L&F).

Is Ocean new to Java 1.5 ? Because my Jedit 4.2pre9 with Java 1.4.2 just knows the L&F styles Metal, Motif, Winblows.
However I'm happy with JEdit's Metal L&F since it doesn't use bold fonts for menus etc. And thanks to your smart hint with the -D switch I can tell JBuilder, Paradigm, and many more to do the same. :-)
Offline overnhet

Junior Member




Java games rock!


« Reply #15 - Posted 2004-03-10 13:22:57 »

Ocean is the new default Metal theme. It replaces the previous one (named Steel) as of JDK 1.5. And it's really nice.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #16 - Posted 2004-03-10 13:38:46 »

Quote

Never had to do that. However JEdit has a background plugin which does it. Since the source are available you could look in it.


Ah...looking at the source, it appears jEdit does something completely different, I'm afraid. And much, much easier (and almost entirely useless).

I mean for ALL swing components - i.e. everything from JMenuBar's to JDialog's - to set a background image (tiled).

This is what RISC OS used to do; you could specify textures for "all scrollbars" or "all menus" etc. Like skinning, but much less anally retentive to the user (only requires a simple set of settings) and actually quite useful :).

"skinnable" GUI's are largely a waste of time (probably this is partly why Sun hasn't bothered documenting the LaF); RISC OS's system was simple enough for anyone to use, and only took a few seconds.

malloc will be first against the wall when the revolution comes...
Offline Bombadil

Senior Member





« Reply #17 - Posted 2004-03-10 14:17:50 »

Quote

"skinnable" GUI's are largely a waste of time (probably this is partly why Sun hasn't bothered documenting the LaF); RISC OS's system was simple enough for anyone to use, and only took a few seconds.

Fully agreed. Usually I hate "skinnable" GUIs too because every apps looks and feels different on the same desktop. :-(  {No critic for SUN because their three L&Fs help the different platforms' users to feel "home".}

I just started the thread to overcome that ugly boldfont in the "old" Metal L&F; having been inspired by JEdit which already does overcome it. :-)

However, since Ocean will be the new Metal with Java 1.5, I think I'm happy then.
Offline overnhet

Junior Member




Java games rock!


« Reply #18 - Posted 2004-03-10 14:38:45 »

Sorry blahblahblahh, I don't know how you could do this without rolling your own L&F.  Sad

Maybe L&F multiplexing (javax.swing.plaf.multi) could be useful. If I understood correctly the purpose of this package, it is used to combine several L&F. Yours would simply draw the image background and others would draw the "real" GUI above.

However I never used it and there would be issues if a L&F filled your background with one color (which is likely to be the case).
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.

E.R. Fleming (19 views)
2014-07-29 03:07:13

E.R. Fleming (7 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!