 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Michael Taylor Guest
|
Posted: Sat Jun 26, 2004 5:48 pm Post subject: OSX and cross-platform code |
|
|
I have a routine that overrides the ComboBoxUI as part of a date popup
routine. I am trying to develop code that will run unchanged on OSX, Windows
and Linux. The following code works fine on OSX, but if I run the class on
any other implementation, it throws a ClassDefNotFound exception for the
apple.laf classes even though the other look and feels are in place.
Any ideas how I can keep the apple code but make the java code more
portable?
public void updateUI() {
ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this);
try {
if (cui instanceof MetalComboBoxUI) {
cui = new MetalDateComboBoxUI();
} else if (cui instanceof MotifComboBoxUI) {
cui = new MotifDateComboBoxUI();
} else if (cui instanceof WindowsComboBoxUI) {
cui = new WindowsDateComboBoxUI();
} else if (cui instanceof apple.laf.AquaComboBoxUI) {
cui = new AquaDateComboBoxUI();
}
setUI(cui);
}
catch (Exception e) {
}
}
|
|
| Back to top |
|
 |
ak Guest
|
Posted: Sat Jun 26, 2004 6:35 pm Post subject: Re: OSX and cross-platform code |
|
|
| Quote: | I have a routine that overrides the ComboBoxUI as part of a date popup
routine. I am trying to develop code that will run unchanged on OSX,
Windows
and Linux. The following code works fine on OSX, but if I run the class on
any other implementation, it throws a ClassDefNotFound exception for the
apple.laf classes even though the other look and feels are in place.
public void updateUI() {
ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this);
try {
if (cui instanceof MetalComboBoxUI) {
cui = new MetalDateComboBoxUI();
} else if (cui instanceof MotifComboBoxUI) {
cui = new MotifDateComboBoxUI();
} else if (cui instanceof WindowsComboBoxUI) {
cui = new WindowsDateComboBoxUI();
} else if (cui instanceof apple.laf.AquaComboBoxUI) {
cui = new AquaDateComboBoxUI();
}
setUI(cui);
}
catch (Exception e) {
}
}
|
you goes wrong way here.
If you want to create (J)DateComboBox you should _register_ your component
UI.
Register is simple:
public class DateComboBox extends JComboBox {
static {
checkUI();
UIManager.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
checkUI();
}
});
}
private static void checkUI() {
String lafName = UIManager.getLookAndFeel().getName().toLowerCase();
if(lafName.indexOf("motif") != -1) {
UIManager.put("DateComboBox ", _package + ".MotifDateComboBoxUI");
}
else if(lafName.indexOf("windows") != -1) {
UIManager.put("DateComboBox ", _package + ".WindowsDateComboBoxUI");
}
else if(lafName.indexOf("metal") != -1) {
UIManager.put("DateComboBox ", _package + ".MetalDateComboBoxUI");
}
else if(<check apple here>) {
UIManager.put("DateComboBox ", _package + ".AquaDateComboBoxUI");
}
}
}
--
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
|
|
| Back to top |
|
 |
Michael Taylor Guest
|
Posted: Sat Jun 26, 2004 7:01 pm Post subject: Re: OSX and cross-platform code |
|
|
Thanks for your reply. I'm new to Swing and am trying your suggestion. I
keep getting an error on the "_package" in your example code (Cannot resolve
symbol). I'm probably missing something! Your help would again be
appreciated.
On 6/26/04 2:35 PM, in article cbkflb$bad$1 (AT) online (DOT) de, "ak"
<spam (AT) imagero (DOT) com> wrote:
| Quote: | I have a routine that overrides the ComboBoxUI as part of a date popup
routine. I am trying to develop code that will run unchanged on OSX,
Windows
and Linux. The following code works fine on OSX, but if I run the class on
any other implementation, it throws a ClassDefNotFound exception for the
apple.laf classes even though the other look and feels are in place.
public void updateUI() {
ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this);
try {
if (cui instanceof MetalComboBoxUI) {
cui = new MetalDateComboBoxUI();
} else if (cui instanceof MotifComboBoxUI) {
cui = new MotifDateComboBoxUI();
} else if (cui instanceof WindowsComboBoxUI) {
cui = new WindowsDateComboBoxUI();
} else if (cui instanceof apple.laf.AquaComboBoxUI) {
cui = new AquaDateComboBoxUI();
}
setUI(cui);
}
catch (Exception e) {
}
}
you goes wrong way here.
If you want to create (J)DateComboBox you should _register_ your component
UI.
Register is simple:
public class DateComboBox extends JComboBox {
static {
checkUI();
UIManager.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
checkUI();
}
});
}
private static void checkUI() {
String lafName = UIManager.getLookAndFeel().getName().toLowerCase();
if(lafName.indexOf("motif") != -1) {
UIManager.put("DateComboBox ", _package + ".MotifDateComboBoxUI");
}
else if(lafName.indexOf("windows") != -1) {
UIManager.put("DateComboBox ", _package + ".WindowsDateComboBoxUI");
}
else if(lafName.indexOf("metal") != -1) {
UIManager.put("DateComboBox ", _package + ".MetalDateComboBoxUI");
}
else if(<check apple here>) {
UIManager.put("DateComboBox ", _package + ".AquaDateComboBoxUI");
}
}
}
|
|
|
| Back to top |
|
 |
ak Guest
|
Posted: Sat Jun 26, 2004 9:22 pm Post subject: Re: OSX and cross-platform code |
|
|
| Quote: | Thanks for your reply. I'm new to Swing and am trying your suggestion. I
keep getting an error on the "_package" in your example code (Cannot
resolve
symbol). I'm probably missing something! Your help would again be
appreciated.
|
_package + ClassName = Full Qualified Class Name;
for example if MetalDateComboBoxUI is in package com.gui.plaf then you init
_package as follows:
static final String _package = "com.gui.plaf";
--
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|