Skip to main content

Different look and feel for 2 JFrames running in the same JVM

5 replies [Last post]
paulmfarrar
Offline
Joined: 2006-06-19
Points: 0

Hi all,

I have a legacy application that I'm trying to bring into the 21st century. It currently uses no look and feel, it instead sets background colours manually - yes I know.

This application uses several separate JFrames to display different types of data, there will be many JFrames open at the same time. I have developed a new JFrame for our users and want to attach a look and feel to it.

Is it possible to attach a look and feel to my JFrame without changing the display of the existing ones?

I know this is quite a strange request but there is a lot of politics involved in this change and we want to make our new frame look good whilst not changing the way everything else looks.

I have searched everywhere on the web and all I can find is the auxiliary look and feel functionality. I'm not sure if this will work or that it's intended for this kind of use.

Thanks very much for your help,

Paul.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
paulmfarrar
Offline
Joined: 2006-06-19
Points: 0

Hi All,

I guess I didn't really describe my problem correctly for you. I have a legacy Java app used widely in my organisation. This app is structured with one main entry point that gives the user options to launch tools, each in a separate JFrame, the tools are developed and managed by separate teams.

I don't want my new development to affect other parts of the existing application. The existing app doesn't define a PLAF instead it uses the default and sets background colours for most components. I want my development to define a PLAF and use that for the colours. As I mentioned I have looked around and it seems that each JVM is only ever meant to support a single PLAF (as one would expect). I was asking if anyone knew a way I could use a different one for my development.

Ewin - Thanks for your comments. I figured it would be a difficult, if not impossible, task. I think I'll investigate other possibilities. Oh and I think I'll stick with my job thanks.

Pietblok - Thanks for the suggestion. I'll take a look at your project and see if it fits. Only problem I can see is that we are still stuck on Java 1.4 and have been waiting for an upgrade for nearly a year.

tball - Thanks for your suggestion. I'll take a look at that.

Thanks,

Paul.

paulmfarrar
Offline
Joined: 2006-06-19
Points: 0

Forgot to mark the question as answered. Thanks for the suggestions.

tball
Offline
Joined: 2003-06-10
Points: 0

> PLAFs aren't attached on a per-JFrame level. They are attached on a per-VM level. Are
> you sure you are interested in changing the PLAF, or do you maybe want a theme?

I implemented PLAF support to be on a per-ThreadGroup basis, to support applets. Unless someone ripped out sun.awt.AppContext (which is ThreadGroup-based), it should still work.

> Is it possible to attach a look and feel to my JFrame
> without changing the display of the existing ones?

> It is almost impossible to mix PLAFs within one application. I have seen a few attempts,
> all failed. Are you sure you are talking about PLAFs?

Try running AppletViewer with two applets that each set different PLAFs. You are correct that a normal Swing app, which resides in one ThreadGroup, won't work. However, if a developer is willing to split his application into separate parts it is indeed possible. Try adapting the AppletViewer code to serve as a display controller where different *lets display with different PLAFs -- these displayers don't have to be applets (although that might be easiest), just running in separate ThreadGroups.

ewin
Offline
Joined: 2005-07-15
Points: 0

You are mixing up several things, I'll try to sort a few things out.

> I have a legacy application that I'm trying to bring
> into the 21st century. It currently uses no look and
> feel, it instead sets background colours manually -
> yes I know.

If it is based on Swing it uses a Look & Feel (a PLAF), whether you like it or not. If it is based on AWT only, it uses native widgets, thus inheriting parts of the platform's LnF.

> This application uses several separate JFrames to
> display different types of data,

So there is a PLAF in use.

> there will be many
> JFrames open at the same time. I have developed a new
> JFrame for our users and want to attach a look and
> feel to it.

PLAFs aren't attached on a per-JFrame level. They are attached on a per-VM level. Are you sure you are interested in changing the PLAF, or do you maybe want a theme?

> Is it possible to attach a look and feel to my JFrame
> without changing the display of the existing ones?

It is almost impossible to mix PLAFs within one application. I have seen a few attempts, all failed. Are you sure you are talking about PLAFs?

Trying to use more than one PLAF breaks in very ugly ways. There are many VM-global resources belonging to a PLAF, including native libraries. Trying to use more than one PLAF means all but one don't have the right resources available. What I have seen were always attempts to manually attach UI delegates from another PLAF to components, using the setUI() method. This is tedious and, as already written, breaks in many ugly ways.

> I know this is quite a strange request but there is a
> lot of politics involved in this change

Then bail out of the job. Politics in software development is never good, and you apparently lack the in-depth technical understanding of the Java GUI system to counter politics with a rational technical statement.

> and we want
> to make our new frame look good whilst not changing
> the way everything else looks.

So to ensure maximum confusion for your users? This is not a great idea from a usability point of view.

> I have searched everywhere on the web and all I can
> find is the auxiliary look and feel functionality.

You mean the multiplexing PLAF? The multiplexing PLAF is junk. It is one of those nonsensically, useless, random things added to SE when the Sun Java GUI developers were bored. More precisely, when they wanted to avoid having to fix some real world bugs but still wanted to appear busy. The multiplexing PLAF is not documented in any acceptable way. It is a solution in search of a problem. Its purpose is not specified other than its purpose being its existence. No one, maybe not even the authors know what it is good for. What it does do is to distribute one event to multiple UI delegates of the same component. Hardly the LnF mixture you are looking for.

> I'm not sure if this will work

It won't.

> or that it's intended
> for this kind of use.

The multiplexing PLAF has no intended use. It is just bit cruft.

pietblok
Offline
Joined: 2003-07-17
Points: 0

Ewin

That is a very sad story you tell about the Multiplexing Look and Feel.

I spent about a year of my spare time to develop a framework for dynamic internationalization that is based upon that Multiplexing L&F. It is far from perfect, a lot of work is still to be done in coding, documentation and explanation, but nevertheless I am pleased with what I achieved so far.

Yesterday I announced the pre release on the Desktop Product announcement forum.

Please be so kind and have a look (http://www.pbjar.org) and give some feedback.

No need to be polite, I really want to know what people think of it.

Thanks,

Piet Blok