Help installing a custom look and feel
From: Edd Grant (edd_at_mredd.co.uk)
Date: 03/22/05
- Next message: Thomas Fritsch: "Re: Help installing a custom look and feel"
- Previous message: Igor Urdenko via JavaKB.com: "Problem: Font appears smaller than expected in JTextPane"
- Next in thread: Thomas Fritsch: "Re: Help installing a custom look and feel"
- Reply: Thomas Fritsch: "Re: Help installing a custom look and feel"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Mar 2005 10:12:43 -0800
Hi,
As part of a current Uni assignment I am required to write a
customised Look and Feel(LAF) and implement it in a java app. So far I
have taken an existing LAF and *cough* modified it by renaming all the
class instances and package paths to a package I have created for it.
The idea was to first get this working effectively (i.e. to be applied
to the app GUI) so I could begin to truly modify it and make my own
LAF.
I currently have a combobox which is populated (manually at the moment
from a Vector) with the available system LAFs. On the mouseClicked
event of a JButton the LAF is changed using the Vector content.
This is the code which populates the combo box data Vector called
"lookAndFeels":
lookAndFeels.add(UIManager.getSystemLookAndFeelClassName());
lookAndFeels.add("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
lookAndFeels.add(UIManager.getCrossPlatformLookAndFeelClassName());
lookAndFeels.add("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
lookAndFeels.add("javax.swing.plaf.metal.MetalLookAndFeel");
lookAndFeels.add("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
// This (below) is the LAF that I have created
lookAndFeels.add("customlafs.abclookandfeel.ABCLookAndFeel");
When a jButton (jButton1) is clicked it calls the
UIManager.setLookAndFeel() function passing the relevant Vector
content according to the current selectino of the combo box. The code
for this is below:
void jButton1_mouseClicked(MouseEvent e)
{
if (comboLAF.getSelectedItem().equals("")) {
JOptionPane.showMessageDialog(null, "Error! Please make a
selection!");
}
else {
try {
UIManager.setLookAndFeel( (String)
lookAndFeels.elementAt(comboLAF.
getSelectedIndex()));
SwingUtilities.updateComponentTreeUI(this);
}
catch (Exception ne) {
JOptionPane.showMessageDialog(null, "Error! \n "
+ (String) lookAndFeels.elementAt(comboLAF.getSelectedIndex())
+ " is not available on this system");
}
}
The problem I am having is that while I can access all the standard
LAFs (Windows, Motif etc) I don't seem to be able to *install* my
custom one (customlafs.abclookandfeel.ABCLookAndFeel). Each time I try
to do so it throws the exception in the code above. I imagine this is
because I have to first "install" the LAF before I can use it? I have
searched and searched for documentation relating to this problem but
can't find a definitive answer.
>From looking at the UIManager functions I found the
addAuxiliaryLookAndFeel() method which takes a LookAndFeel object as
an argument. I thought this would work but because LookAndFeels are
abstract classes I can't make an instance of my custom LAF to pass as
an argument to this function. As a result I am totally stumped. To be
honest I'm not even sure if this is the right function or approach to
take.
If anyone has any insight as to how I can make my custom LAF available
for use in the App GUI I would be very grateful to hear your thoughts!
I have tried to provide all the necessary info but if I have left
something out please don't hesitate to ask me for it.
Cheers,
Edd
http://www.mredd.co.uk
email:edd@nospam:mredd.co.uk
(remove nospam: to email me)
- Next message: Thomas Fritsch: "Re: Help installing a custom look and feel"
- Previous message: Igor Urdenko via JavaKB.com: "Problem: Font appears smaller than expected in JTextPane"
- Next in thread: Thomas Fritsch: "Re: Help installing a custom look and feel"
- Reply: Thomas Fritsch: "Re: Help installing a custom look and feel"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]