I believe the only thing different with this is the version of SceneBuilder is 8.3 and I am using TreeTableView and TreeTableColumn with Oracle Java 8
Here is the fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.control.TreeTableView?>
<TreeTableView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="1" minWidth="1" prefHeight="400.0" prefWidth="600.0" showRoot="false" stylesheets="#org/cornova/AudioExplorer.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.cornova.AudioExplorerController">
<columns>
<TreeTableColumn fx:id="mixerName" editable="false" maxWidth="6000.0" minWidth="100.0" prefWidth="-1.0" text="Mixers" />
<TreeTableColumn fx:id="lineNames" maxWidth="49.0" minWidth="100.0" prefWidth="-1.0" text="Lines" />
<TreeTableColumn fx:id="controlNames" minWidth="100.0" prefWidth="-1.0" text="Controls" />
<TreeTableColumn fx:id="formatsNames" minWidth="100.0" prefWidth="-1.0" text="Formats" />
</columns>
</TreeTableView>
Here is the controller class
/**
* Sample Skeleton for 'AudioExplorer.fxml' Controller Class
*/
package org.cornova;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.TreeTableColumn;
public class AudioExplorerController {
#FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
#FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
#FXML // fx:id="mixerName"
private TreeTableColumn<?, ?> mixerName; // Value injected by FXMLLoader
#FXML // fx:id="lineNames"
private TreeTableColumn<?, ?> lineNames; // Value injected by FXMLLoader
#FXML // fx:id="controlNames"
private TreeTableColumn<?, ?> controlNames; // Value injected by FXMLLoader
#FXML // fx:id="formatsNames"
private TreeTableColumn<?, ?> formatsNames; // Value injected by FXMLLoader
#FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert mixerName != null : "fx:id=\"mixerName\" was not injected: check your FXML file 'AudioExplorer.fxml'.";
assert lineNames != null : "fx:id=\"lineNames\" was not injected: check your FXML file 'AudioExplorer.fxml'.";
assert controlNames != null : "fx:id=\"controlNames\" was not injected: check your FXML file 'AudioExplorer.fxml'.";
assert formatsNames != null : "fx:id=\"formatsNames\" was not injected: check your FXML file 'AudioExplorer.fxml'.";
}
}
Here is the main class
package org.cornova;
import java.net.URL;
import javafx.application.Application;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.TreeTableColumn.CellDataFeatures;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.stage.Stage;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.Mixer.Info;
/**
*
* #author walt
*/
public class AudioExplorer extends Application {
private URL url;
private FXMLLoader explorerLoader;
private AudioExplorerController audioController;
#Override
public void start(Stage stage) throws Exception {
stage.setTitle("Audio Explorer");
final Scene scene = new Scene(new Group(), 200, 400);
Group sceneRoot = (Group)scene.getRoot();
try {
url = getClass().getResource("/AudioExplorer.fxml");
explorerLoader = new FXMLLoader(url);
explorerLoader.setLocation(url);
audioController = explorerLoader.getController();
} catch (Exception e) {
System.out.println(e);
}
//Creating the root element
TreeItem rootNode = new TreeItem();
rootNode.setExpanded(true);
Info mixers[] = AudioSystem.getMixerInfo();
rootNode = new TreeItem<>(mixers[0]);
//Creating tree items
for (int i = 0; i < mixers.length; i++) {
rootNode.getChildren().add(new TreeItem<>(mixers[i]));
}
//Creating a column
TreeTableColumn<Info,String> mixerInfo = new TreeTableColumn<>("Mixers");
mixerInfo.setMaxWidth(1500);
//Defining cell content
mixerInfo.setCellValueFactory((CellDataFeatures<Info, String> p) ->
new ReadOnlyStringWrapper(p.getValue().getValue().getName()));
//Creating a tree table view
final TreeTableView<Info> treeTableView = new TreeTableView<>(rootNode);
treeTableView.getColumns().add(mixerInfo);
treeTableView.setMaxWidth(1500);
treeTableView.setShowRoot(false);
treeTableView.autosize();
sceneRoot.getChildren().add(treeTableView);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
This is all done under netbeans 8.2. I've done, perhaps a couple dozen of these scene builder based graphic apps perhaps 18 months ago. One thing I discovered back then was to insure the location of the css and controller source were adjusted for the name space they'd be in, which is reflected in the fxml.
The css file is empty as I only defined it in SceneBuilder at this point, which is why I did not include it (only comments).
One think I do recall from when I was starting with SceneBuilder is it's proclivity to fail silently.
Tnanks!
You actually need to load the fxml for the controller to be created based on the fxml. Also passing the location twice is not necessary:
url = getClass().getResource("/AudioExplorer.fxml");
explorerLoader = new FXMLLoader(url);
try {
TreeTableView<?> audioExplorer = explorerLoader.load();
audioController = explorerLoader.getController();
...
} catch ...
Furthermore there is little reason to keep a reference to the FXMLLoader instance in a field. Once you're done loading simply extract the information you need and "drop" the loader reference. Calling load a second time should be avoided anyways...
In addition to fabian's answer, please note that I've written some utility methods, which can reduce FXML-loading to a single statement, such as:
TreeTableView<?> audioExplorer = FXMLLoaders.load(AudioExplorer.class);
Please note, this is only possible though, if you stick to the following naming convention:
If a class "mypackage.<name>" loads a FXML file, then the FXML file
should be in the same package and be named "<name>.fxml".
The library is Open Source. Maybe you find it useful:
<dependency>
<groupId>org.drombler.commons</groupId>
<artifactId>drombler-commons-fx-core</artifactId>
<version>0.10</version>
</dependency>
You can read more about it here:
http://puces-blog.blogspot.ch/2015/03/drombler-commons-conventions-to.html
Related
I want to maintain single background color(black) for all panes, and for all views. i don't want write css for every view. i am using only vbox and hbox mostly. and very few table views. is there any easy way to write css once and apply to all. thank you in advance
You don't write a css for every view, you give every element the same style class.
Pane pane = new Pane();
pane.getStyleClass().add("bg-black-style");
Somewhere you need to add the stylesheet to the scene
scene.getStylesheets().add("css-file.css");
And in the css file
.bg-black-style {
-fx-background-color: black;
}
This way every thing that should look the same has it's style all in one place.
You can just use .pane in CSS class, and it will work for all the panes.
.pane{
-fx-background-color: black;
}
Same works with .button etc.
You can apply the style sheet to the entire application like this:
package hacks;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
import java.net.URL;
/**
* Created by BDay on 7/10/17.<br>
* <br>
* CssStyle sets the style for the entire project
*/
public class CssStyle extends Application {
private String yourCss = "YourResource.css";
public CssStyle() {
try {
Application.setUserAgentStylesheet(getCss()); //null sets default style
} catch (NullPointerException ex) {
System.out.println(yourCss + " resource not found");
}
}
private Button button = new Button("Button Text");
private TextArea textArea = new TextArea("you text here");
private ObservableList<String> listItems = FXCollections.observableArrayList("one", "two", "three");
private ListView listView = new ListView<String>(listItems);
private FlowPane root = new FlowPane(button, textArea, listView);
private Scene scene = new Scene(root);
#Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(scene);
primaryStage.show();
}
private String getCss() throws NullPointerException {
ClassLoader classLoader = getClass().getClassLoader();
URL resource = classLoader.getResource(yourCss);
String asString = resource.toExternalForm(); //throws null
return asString;
}
}
I want to have some helper functions for manipulating UI.
I don't want to pass to them any parameters except what is necessary by my domain model (i don't want to pass EModelService, EPartService etc.)
Question: The problem is i am getting exception application does not have active window.
I found where the problem is.
It happend because i am manipulating parts via EPartService accessed from the application context IWorkbench.getApplication().getContext().get(EPartService.class).
THIS IS IMPORTANT: Currently i am getting that exception when i am trying to modify my UI AFTER i read inputs from dialog. Pleas note that the error does not happened when i am trying to modify the UI just BEFORE i
opened the dialog. Look at the code, i added some comments.
NewFromDirectoryDialog.java
package cz.vutbr.fit.xhriba01.bc.handlers;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import cz.vutbr.fit.xhriba01.bc.BcModel;
import cz.vutbr.fit.xhriba01.bc.resolvers.filesystem.FileSystemResolver;
import cz.vutbr.fit.xhriba01.bc.ui.dialogs.NewFromDirectoryDialog;
import cz.vutbr.fit.xhriba01.bc.ui.UI;
public class NewFromDirectoryHandler {
#Execute
public void execute(MApplication application, EPartService partService, #Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
FileSystemResolver fsr = new FileSystemResolver("/home/jara/git/cz.vutbr.fit.xhriba01.bc/bc/src",
"/home/jara/git/cz.vutbr.fit.xhriba01.bc/bc/bin");
BcModel.setResolver(fsr);
// THIS CALL IS OK AND EVERYTHING WORKS
UI.changeExplorerView("bc.partdescriptor.filesystemview", fsr);
NewFromDirectoryDialog dialog = new NewFromDirectoryDialog(shell);
dialog.create();
if (dialog.open() == Window.OK) {
String sourceDir = dialog.getSourceDir();
String classDir = dialog.getClassDir();
FileSystemResolver fsr = new FileSystemResolver(classDir, sourceDir);
//THIS CALL LEADS TO EXCEPTION: application does not have active window
UI.changeExplorerView("bc.partdescriptor.filesystemview", fsr);
}
}
}
That EPartService from application context is based on org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl
and not on org.eclipse.e4.ui.internal.workbench.PartServiceImpl
as EPartService instance you get when injected to #PostConstruct annotated method on Part's view.
org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl (not entire source code)
You can see that the error probably happened because at the time ApplicationPartServiceImpl.createPart is called in my UI.changeExplorerView, the Eclipse runtime does not know what window
is currently active.
package org.eclipse.e4.ui.internal.workbench;
import java.util.Collection;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MInputPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.IPartListener;
public class ApplicationPartServiceImpl implements EPartService {
private MApplication application;
#Inject
ApplicationPartServiceImpl(MApplication application) {
this.application = application;
}
private EPartService getActiveWindowService() {
IEclipseContext activeWindowContext = application.getContext().getActiveChild();
if (activeWindowContext == null) {
throw new IllegalStateException("Application does not have an active window"); //$NON-NLS-1$
}
EPartService activeWindowPartService = activeWindowContext.get(EPartService.class);
if (activeWindowPartService == null) {
throw new IllegalStateException("Active window context is invalid"); //$NON-NLS-1$
}
if (activeWindowPartService == this) {
throw new IllegalStateException("Application does not have an active window"); //$NON-NLS-1$
}
return activeWindowPartService;
}
#Override
public MPart createPart(String id) {
return getActiveWindowService().createPart(id);
}
}
LifeCycleManager.java (how i initialize the UI helper class)
You can see i am injecting IWorkbench to my UI class.
IWorkbench allows me to access MApplication, so that is all i should
need to modify app UI.
package cz.vutbr.fit.xhriba01.bc;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.e4.ui.workbench.UIEvents;
import cz.vutbr.fit.xhriba01.bc.ui.UI;
public class LifeCycleManager {
#Inject
#Optional
private void appCompleted(#UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Object event, IWorkbench workbench) {
ContextInjectionFactory.inject(UI.getDefault(), workbench.getApplication().getContext());
}
}
UI.java
package cz.vutbr.fit.xhriba01.bc.ui;
import javax.inject.Inject;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.jface.text.IDocument;
import cz.vutbr.fit.xhriba01.bc.BcModel;
import cz.vutbr.fit.xhriba01.bc.resolvers.ISourceAndClassResolver;
public class UI {
public static final String PART_EXPLORER_ID = "bc.part.inspector";
public static final String PART_EXPLORER_CONTAINER_ID = "bc.partstack.explorer_stack";
public static final String PART_JAVA_SOURCE_VIEWER_ID = "bc.part.javasourceview";
private static UI fInstance = new UI();
#Inject
private IWorkbench fWorkbench;
private UI() {
}
public static void changeExplorerView(String partDescriptorId, ISourceAndClassResolver resolver) {
EModelService modelService = fInstance.fWorkbench.getApplication().getContext().get(EModelService.class);
EPartService partService = fInstance.fWorkbench.getApplication().getContext().get(EPartService.class);
MApplication application = fInstance.fWorkbench.getApplication();
MPart part = partService.createPart(partDescriptorId);
MPart oldPart = partService.findPart(UI.PART_EXPLORER_ID);
MPartStack partStack = (MPartStack) modelService.find(UI.PART_EXPLORER_CONTAINER_ID, application);
partStack.setVisible(true);
if (oldPart != null) {
partService.hidePart(oldPart);
}
part.setElementId(UI.PART_EXPLORER_ID);
partStack.getChildren().add(part);
BcModel.setResolver(resolver);
partService.showPart(part, PartState.VISIBLE);
}
public static UI getDefault() {
return fInstance;
}
public static void setJavaSourceLabel(String label, EPartService partService) {
MPart part = partService.findPart(UI.PART_JAVA_SOURCE_VIEWER_ID);
if (part != null) {
part.setLabel(label);
}
}
public static void setJavaSourceText(String source) {
IDocument document = BcModel.getJavaDocument();
if (document != null) {
document.set(source);
}
}
}
I think the problem is when i open the dialog, the activeChild changes somehow to that new opened dialog and when i close it and try immediately change my UI, it does not work because the activeChild is still not properly setup back. Otherweise i don't know why it works fine just before i opened the dialog and doesn't work just after the dialog is closed.
Does anyone know if it is bug?
I assign styleclass of ToggleButton in FXML file as follows:
<ToggleButton fx:id="Button" styleClass="defaultStyle">
Later, in my code I change the style classes as follows:
#FXML private ToggleButton Button;
Button.getStyleClass().remove("defaultStyle");
Button.getStyleClass().add("newStyle");
The CSS file is defined as:
.defaultStyle { -fx-background-color: black;}
.newStyle { -fx-background-color: red;}
EDITED:
The new style is applied when done in the Controller, but the new style is not being applied when done somewhere else. When I debug, I see the correct style-class being added & removed to the button.
Anyone got a workaround for this problem? I appreciate your help in advance.
Style class removing and adding are working as expected. I guess your problem is the ToggleButton has not been injected correctly, it should be:
#FXML private ToggleButton Button;
...
Button.getStyleClass().remove("defaultStyle");
Button.getStyleClass().add("newStyle");
in the controller class. Note the capital b of "Button" since you have defined fx:id="Button" in FXML file. Also note that you don't need to instantiate the ToggleButton Button (like new ToggleButton()) yourself.
EDIT:
Here is code example for changing the styleclass. As I said it is working as expected. Compare it with yours.
Sample.fxml:
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="somepackage.SampleController">
<stylesheets>
<String fx:value="somepackage/style.css" />
</stylesheets>
<children>
<ToggleButton layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="mybutton" styleClass="defaultStyle" />
</children>
</AnchorPane>
SampleController.java:
package somepackage;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ToggleButton;
public class SampleController implements Initializable {
#FXML
private ToggleButton mybutton;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("before :" + mybutton.getStyleClass());
mybutton.getStyleClass().remove("defaultStyle");
mybutton.getStyleClass().add("newStyle");
System.out.println("after :" + mybutton.getStyleClass());
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
MainDemo.java:
package somepackage;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainDemo extends Application {
#Override
public void start(Stage stage) throws Exception {
System.out.println("version: " + com.sun.javafx.runtime.VersionInfo.getRuntimeVersion());
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The css file includes selectors of yours.
Since you said it is only done when the controller does it.
Use the FXMLLoader to load your controller. then you change the StyleClass to the newStyle.
I am looking to read xls file using the gwt RPC and when I am using the code which excecuted fine in normal file it is unable to load the file and giving me null pointer exception.
Following is the code
{
{
import com.arosys.readExcel.ReadXLSX;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.Preview.client.GWTReadXL;
import java.io.InputStream;
import com.arosys.customexception.FileNotFoundException;
import com.arosys.logger.LoggerFactory;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* #author Amandeep
*/
public class GWTReadXLImpl extends RemoteServiceServlet implements GWTReadXL
{
private String fileName;
private String[] Header=null;
private String[] RowData=null;
private int sheetindex;
private String sheetname;
private XSSFWorkbook workbook;
private XSSFSheet sheet;
private static Logger logger=null;
public void loadXlsxFile() throws Exception
{
logger.info("inside loadxlsxfile:::"+fileName);
InputStream resourceAsStream =ClassLoader.getSystemClassLoader().getSystemResourceAsStream("c:\\test2.xlsx");
logger.info("resourceAsStream-"+resourceAsStream);
if(resourceAsStream==null)
throw new FileNotFoundException("unable to locate give file");
else
{
try
{
workbook = new XSSFWorkbook(resourceAsStream);
sheet = workbook.getSheetAt(sheetindex);
}
catch (Exception ex)
{
logger.error(ex.getMessage());
}
}
}// end loadxlsxFile
public String getNumberOfColumns() throws Exception
{
int NO_OF_Column=0; XSSFCell cell = null;
loadXlsxFile();
Iterator rowIter = sheet.rowIterator();
XSSFRow firstRow = (XSSFRow) rowIter.next();
Iterator cellIter = firstRow.cellIterator();
while(cellIter.hasNext())
{
cell = (XSSFCell) cellIter.next();
NO_OF_Column++;
}
return NO_OF_Column+"";
}
}
}
I am calling it in client program by this code:
final AsyncCallback<String> callback1 = new AsyncCallback<String>() {
public void onSuccess(String result) {
RootPanel.get().add(new Label("In success"));
if(result==null)
{
RootPanel.get().add(new Label("result is null"));
}
RootPanel.get().add(new Label("result is"+result));
}
public void onFailure(Throwable caught) {
RootPanel.get().add(new Label("In Failure"+caught));
}
};
try{
getService().getNumberOfColumns(callback1);
}catch(Exception e){}
}
Pls tell me how can I resolve this issue as the code runs fine when run through the normal java file.
Why are using using the system classloader, rather than the normal one?
But, If you still want to use then look at this..
As you are using like a web application. In that case, you need to use the ClassLoader which is obtained as follows:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
This one has access to the all classpath paths tied to the webapplication in question and you're not anymore dependent on which parent classloader (a webapp has more than one!) has loaded your class.
Then, on this classloader, you need to just call getResourceAsStream() to get a classpath resource as stream, not the getSystemResourceAsStream() which is dependent on how the webapplication is started. You don't want to be dependent on that as well since you have no control over it at external hosting:
InputStream input = classLoader.getResourceAsStream("filename.extension");
The location of file should in your CLASSPATH.
I am having trouble getting images to display when using ImageBundle. I have followed the GWT tutorial as a guide however my images don't display.
I can view the images (from within Eclipse) in my browser fine - so they are definitely there. I am clearly doing something wrong when using the ImageBundle but I'm at a loss to understand what it is I am doing wrong.
The logo.jpg image should simply display itself.
The ajaxLoader.gif should display itself first (in order to cover the RPC which gets the facebook user profile data) and then it would be replaced by the image at the pic_square url.
When I look at the GWT generated html, I find that where the logo.jpg image should be, there is a gif image [http://sandpit1965.appspot.com/sandpit/clear.cache.gif] but I don't understand where this is coming from.
Any help would be appreciated - source code below.
Darren
Image Package Structure
org.redboffin.sandpit.client.icons
|___ SandpitImageBundle.java
|___ ajaxLoader.gif
|___ logo.jpeg
Relevent Classes
package org.redboffin.sandpit.client.facebook;
import org.redboffin.sandpit.client.icons.SandpitImageBundle;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ErrorEvent;
import com.google.gwt.event.dom.client.ErrorHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.XMLParser;
public class ProfileWidget extends Composite implements RBWidget {
// Data
private String firstName = null;
private String lastName = null;
private String picSquareUrl = null;
// Elements
private Image picSquare = new Image();
private Image logo = new Image();
private Button logoutButton = new Button("Logout");
private DockPanel panel = new DockPanel();
private HTML html = new HTML("Welcome to Sandpit.");
/**
* Create a remote service proxy to talk to the server-side User Data
* service.
*/
private final UserDataServiceAsync userDataService = GWT.create(UserDataService.class);
public ProfileWidget() {
this.rpcWidget = new RPCWidget(this);
this.initProfileImage();
this.initLogoImage();
panel.add(picSquare, DockPanel.WEST);
panel.add(html, DockPanel.CENTER);
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.add(logo);
verticalPanel.add(logoutButton);
panel.add(verticalPanel, DockPanel.EAST);
panel.add(rpcWidget, DockPanel.SOUTH);
initWidget(panel);
}
private void initProfileImage() {
// Display ajaxLoader.gif
SandpitImageBundle sib = GWT.create(SandpitImageBundle.class);
AbstractImagePrototype aip = sib.ajaxLoader();
sib.applyTo(this.picSquare);
}
private void initLogoImage() {
// Display logo.jpg
SandpitImageBundle sib = GWT.create(SandpitImageBundle.class);
AbstractImagePrototype aip = sib.logo();
aip.applyTo(this.logo);
}
// Other methods omitted...
}
package org.redboffin.sandpit.client.icons;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.ImageBundle;
public interface SandpitImageBundle extends ImageBundle {
/**
* Would match the file 'logo.jpg', 'logo.gif', or 'logo.png' located in the
* same package as this type.
*/
public AbstractImagePrototype logo();
/**
* Would match the file 'ajaxLoader.jpg', 'ajaxLoader.gif', or 'ajaxLoader.png' located in the
* same package as this type.
*/
public AbstractImagePrototype ajaxLoader();
}
I don't understand why but this now works and I haven't changed anything.
The image won't be displayed until you "compile" your project and place your generated "war" in your servers public folder. You were simply making a request to a non existing file.