我正在使用GWT 2.0,GWT-Ext 1.5&带有Mozilla 3.6.x的Java 1.6。
我正在尝试按照link实现ThemeChanger模块。但我无法实现它。任何人都可以看看我的代码&告诉我我错过了什么或做错了什么?
的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);
}
}
答案 0 :(得分:1)
检查您的主题位置。
您可以下载gxt-2.2.1.zip。
在您的计算机上提取它。将有一个名为resources
的目录包含主题
您需要在项目位置复制。
我已经通过下面的示例值
检查了您的代码new Object[]{"/test/resources/themes/slate/css/xtheme-slate.css", "Slate"},
new Object[]{"/test/resources/themes/access/css/xtheme-access.css", "Access"},
在上面.jar
中给出主题的ThemeChanger
类中
有效。