PopupPanel Not Showing - java

It's late, I'm tired and I can't figure out why a simple popup panel instead of showing as it should, displays a label beneath my. For example:
|SOME CLICKABLE BUTTONS| | |
|SOME MORE OPTIONS | | SOME CONTENT |
|EVEN MORE OPTIONS | | |
|Please wait|
"Please wait" is the label as you can see is created like so in the:
#Override
public void onModuleLoad()
{ ...<snip> //creates
final PopupPanel popup = new PopupPanel(false, true);
popup.add(new Label("Please wait"));
popup.center();
RootPanel.get().add(popup);
Some things you should know:
I'm running this in development mode via Jetty. I'm using reflections without class literals to load my panels because I haven't come round to implementing the workaround using generators (and the application is rather large, so it needs splitting). Though I doubt these things are causing it problems.
Shouldn't upon load, a popup display? My overall goal is to have something which displays a loading gif everytime a new part of the application is loading.

Do not add your PopupPanel to a RootPanel.
Delete this line
RootPanel.get().add(popup);
and it will work.

Related

Codename One event listening within a Container which contains more sub-Containers

I'm using Codename One to develop a mobile app.
I have an outer-Container which I added an ActionListener by invoking the method addPointerReleasedListener to it.
There are more inner-Containers which are NOT added with any listeners.
To illustrate:
outer-Container (added `addPointerReleasedListener` to it)
- An Image Container (NO listener added)
- A Text Container (NO listener added)
--------------------------------------------------------------
| | | |
| | | |
| | Image | Some Text here |
| | | |
| | | |
--------------------------------------------------------------
^ ^ ^
works only if I click/press
here
I noticed that in order to invoke the event, I have to click/press on an area which is not occupied any inner-Containers. That is, it does not work if I click/press on any text and image areas (because there no listeners added to it). I have to specifically click/press on an "empty" area of the outer-Container. Obviously, this does not make sense because I want to make the entire container react the same way when the user clicks/presses anywhere within it.
What is the best method/practice to implement this? (I find it a bit redundant to add the same listener to many inner-Containers.)
Your approach won't work properly on real devices.
Create a button and add your actionListener to it and set your outer container's leadComponent to that button.
Button btn = new Button("");
btn.addActionListener(e -> {
//Your action here
});
outerContainer.setLeadComponent(btn);
You don't have to add that button to your container, just set it as the leadComponent only.

GWT DataGrid does not display, CellTable does

Overview
I have an application that consists of a SplitLayoutPanel that has a StackLayoutPanel with two menu selections on the left and a DeckLayoutPanel on the right. The DeckLayoutPanel has two subpanels, one a SimpleLayoutPanel containing a Label and one a DockLayoutPanel containing a Label and another SimpleLayoutPanel. The last SimpleLayoutPanel contains a DataGrid.
SplitLayoutPanel (TestUI)
|
+ StackLayoutPanel
| |
| + CellList (Profile)
| |
| + CellList (Admin)
|
+ DeckLayoutPanel
|
+ SimpleLayoutPanel
| |
| + Label
|
+ DockLayoutPanel (BudgetPanel)
|
+ Label
|
+ SimpleLayoutPanel (LedgerPanel)
|
+ DataGrid
All subpanels have their height and width set to 100% by their containing panels.
Expected Behavior
The expected behavior is that clicking on the "Budget" menu item in the StackLayoutPanel will show the BudgetPanel, including the LedgerPanel's DataGrid.
Observed Behavior
When the "Budget" menu item is clicked, the DockLayoutPanel is displayed, with its header Label, the DataGrid column headers are displayed, but the DataGrid rows do not appear.
When a Label is added to the south area of the DockLayoutPanel, the application compiles but nothing is displayed, not even the top level StackLayoutPanel.
When the DataGrid is replaced with a CellTable, the data is displayed (although the height of each row is much more than necessary to hold the data).
Questions
What needs to be done to get the DataGrid to display as expected?
How can the rows be styled to have a smaller height?
Source Code
The full source code demonstrating this problem is available on GitHub.
I've looked really fast at your code, and from what I saw, you've set a height of 100% for your datagrid. Unfortunately in GWT, you have to put a fixed value for your datagrid.
datagrid.setHeight("300px");
You can do a workaround by dynamically changing the height of your datagrid.
Window.addResizeHandler(new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
datagrid.setHeight(Window.getClientHeight() - menuSize);
}
});
I got the answer from Thomas Broyer on the GWT mailing list. The trick is to call forceLayout() on the BudgetPanel instance when it is shown in its containing DeckLayoutPanel.
Thanks for all the suggestions.

Opening multiple windows in e4 locks previous windows

I am building an application with E4 and SWT . For a button click, sometimes a new window(shell) is opened. The problem is when I open a new window, I am unable to use the other windows, in a sense, it's getting locked. Unless I close the latest window, cannot access the others. This makes debugging a little difficult. I am not sure if this is due to e4 model or SWT framework.
Could you please tell me why this is and how to overcome this?
Thanks in advance.
I have run into this issue before as I was creating a new window (MWindow) and adding it to a perpective (MPerspective). If this is what you are doing then you have two options:
Add the new window to the application (MApplication) instead of the perspective
Add the tag IPresentationEngine.WINDOW_TOP_LEVEL to the new window. (For more Information see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=441251)
Additional Information to (2): If you also want your window to be minimizable and to have an icon representation in the windows task bar you can use the following setting to configure the renderer
MWindow window = modelService.createModelElement(MTrimmedWindow.class);
window.getTags().add(IPresentationEngine.WINDOW_TOP_LEVEL);
window.getPersistedState().put(IPresentationEngine.STYLE_OVERRIDE_KEY, "" + SWT.SHELL_TRIM);
I found what was wrong.
The shell creation was wrong because I was using APPLICATION_MODAL bit:
shell = new Shell(Display.getCurrent(), SWT.TITLE | SWT.CLOSE | SWT.MAX | SWT.SHELL_TRIM | SWT.APPLICATION_MODAL | SWT.YES | SWT.NO);
It had to be PRIMARY_MODAL:
shell = new Shell(Display.getCurrent(), SWT.TITLE | SWT.CLOSE | SWT.MAX | SWT.SHELL_TRIM | SWT.PRIMARY_MODAL | SWT.YES | SWT.NO);
Thanks for all the help.

Java (JFace Application Window) Setting external label text

I am looking to figure out how to set the text of a label on an external Application Window.
What I have:
I have two windows so far. The first one is the main application window that will appear when the user starts the program. The second window is another separate window that I have created specifically to display a custom error window.
The problem: I seem to be unable to call the label that I have created on the error window and set the text to something custom. Why? I want to be able to reuse this window many times! This window is aimed for things like error handling when there is invalid input or if the application cannot read/save to a file.
I was going to post screen shots but you need 10 rep for that. It would have explained everything better.
Here is the code for the label on the Error_dialog window:
Label Error_label = new Label(container, SWT.NONE);
Error_label.setBounds(10, 10, 348, 13);
Error_label.setText("Label I actively want to change!");
Here is the condition I would like to fire off when it is met:
if(AvailableSpaces == 10){
//Set the label text HERE and then open the window!
showError.open();
}
I have included this at the top of the class as well:
Error_dialog showError = new Error_dialog();
Just save the label as a field in your dialog class and add a 'setter' method. Something like:
public class ErrorDialog extends Dialog
{
private Label errorLabel;
... other code
public void setText(String text)
{
if (errorLabel != null && !errorLabel.isDisposed()) {
errorLabel.setText(text);
}
}
You will need to use your dialog like this:
ErrorDialog dialog = new ErrorDialog(shell);
dialog.create(); // Creates the controls
dialog.setText("Error message");
dialog.open();
Note: you should stick to the rules for Java variable names - they always start with lower case.
Further learn to use Layouts. Using setBounds will cause problems if the user is using different fonts.

Some features of exported SWT Standalone application not working

I've recently developed a SWT Standalone application with eclipse on my Mac OS X. The problem is now that I've finished, I wanted to export my application via the eclipse export to a Runnable Jar file. Everything works fine when I do it on my Mac OS X, but I also want to run the application on Ubuntu and other Unix based distributions.
So I thought I just import my eclipse project into the eclipse application on the respective OS and export the application again as a Runnable Jar. The problem is now that most of the features of my application don't work anymore ... Suddenly simple things like text boxes aren't displayed anymore and buttons don't work anymore.
The strange thing is when I start the application within my eclipse application everything works fine. I desperately tried to find a way of how to solve this problem, but I couldn't find anything yet. Hope someone can help me out here with this problem ...
Is it just a version problem or do I miss something else?
Here is an example code from one of my jface Dialogs that I can open from within my application:
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
// remaining imports omitted
public class ConnectionSettings extends Dialog {
/**
* The current status.
*/
private Text status;
// Other privates fields omitted.
#Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) container.getLayout();
gridLayout.numColumns = 2;
// other initialisation of labels and text fields omitted
Group grpStatus = new Group(container, SWT.NONE);
grpStatus.setLayout(new GridLayout(1, false));
grpStatus.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2,
1));
grpStatus.setText("Status");
// This Text field isn't shown in the exported application
status = new Text(grpStatus, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP
| SWT.H_SCROLL | SWT.V_SCROLL);
status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
// button omitted
return container;
}
// overriding this methods allows you to set the
// title of the custom dialog
#Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("Connection Settings");
}
#Override
protected Point getInitialSize() {
return new Point(450, 348);
}
That's how it looks like when I start my application within eclipse:
That's how it looks like when I start my exported application:
As you can see the text field is just not displayed while everything else works fine.

Categories