问题
I'm using GWT 2.0, GWT-Ext 1.5 & Java 1.6 with Mozilla 3.6.x.
I'm trying to implement ThemeChanger module as per this link. But I'm not able to achieve it. Can anyone look at my code & tell me what am I missing or doing wrong?
Test.html
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="ThemeTest.css">
<link id="theme" rel="stylesheet" type="text/css" href="/public/resources/themes/green/css/xtheme-green.css"/>
<link id="theme" rel="stylesheet" type="text/css" href="/public/resources/themes/red/css/xtheme-red.css"/>
<link id="theme" rel="stylesheet" type="text/css" href="/public/resources/themes/gray/css/xtheme-gray.css"/>
<link id="theme" rel="stylesheet" type="text/css" href=""/>
<title>Web Application Project</title>
<script type="text/javascript" language="javascript" src="themetest/themetest.nocache.js"></script>
</head>
<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
</body>
</html>
Test.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='test'>
<inherits name='com.google.gwt.user.User'/>
<inherits name='com.gwtext.GwtExt' />
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<stylesheet src="resources/css/ext-all.css" />
<stylesheet src="resources/css/style.css" />
<script src="adapter/ext/ext-base.js" />
<script src="ext-all.js" />
<entry-point class='com.test.client.ThemeTest'/>
<source path='client'/>
<source path='shared'/>
</module>
EntryPointClass: ThemeTest.java
@Override
public void onModuleLoad() {
FormPanel formPanel = new FormPanel();
formPanel.setTitle("Form");
TextField nameField = new TextField("Name");
TextField descField = new TextField("Desc");
formPanel.add(nameField);
formPanel.add(descField);
formPanel.add(new ThemeChanger());
RootPanel.get().add(formPanel);
}
ThemeChanger.java
public class ThemeChanger extends ComboBox {
public ThemeChanger() {
final Store store = new SimpleStore(new String[]{"theme", "label"}, new Object[][]{
new Object[]{"/public/resources/themes/green/css/xtheme-green.css", "Green"},
new Object[]{"", "Aero Glass"},
new Object[]{"/public/resources/themes/red/css/xtheme-red.css", "Red"},
new Object[]{"/public/resources/themes/gray/css/xtheme-gray.css", "Gray"},
});
store.load();
setFieldLabel("Select Theme");
setEditable(false);
setStore(store);
setDisplayField("label");
setForceSelection(true);
setTriggerAction(ComboBox.ALL);
setValue("Gray");
setFieldLabel("Switch theme");
addListener(new ComboBoxListenerAdapter() {
public void onSelect(ComboBox comboBox, Record record, int index) {
try {
String theme = record.getAsString("theme");
CSS.swapStyleSheet("theme", theme);
} catch (Exception e) {
e.printStackTrace();
}
}
});
setWidth(100);
}
}
回答1:
Check your locations of themes.
You can download gxt-2.2.1.zip.
Extract it on your computer. there will be a directory named resources
containing themes
which you need to copy at your project location.
I have checked your code by palcing below example values
new Object[]{"/test/resources/themes/slate/css/xtheme-slate.css", "Slate"},
new Object[]{"/test/resources/themes/access/css/xtheme-access.css", "Access"},
In ThemeChanger
classs with themes given in above .jar
It worked.
来源:https://stackoverflow.com/questions/5603880/themechanger-in-gwt-ext