Here is my specific scenario:
I have my application running in the background and I want to open a new window from my applications toolbar icon right click menu. For simplicity I am using a MessageDialog, and using the method open() on the dialog, the window should display and make itself the active window.
For some reason I've run into the problem that if I had some other application open and I try to open this new dialog, it opens, but behind the active application. The new dialog will open in front of the other windows of the same application, but not the other(active) application.
Is there a simple way to do this that I'm missing?
I was able to find a solution. Essentially you need to find your active workbench shell(the application shell) and use the following methods on that shell, followed by pushing the actual desired window to the front.
You could easily modify this to make your window appear maximized as well by adding the method shell.setMaximized(true) before the redraw.
private static void bringupDialog(WindowState state) {
final Shell workbenchShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
//bring up the application to front
workbenchShell.setVisible( true );
workbenchShell.setMinimized( false );
workbenchShell.redraw();
//focus on dialog
workbenchShell.setActive();
workbenchShell.forceActive();
workbenchShell.setFocus();
workbenchShell.forceFocus();
workbenchShell.moveAbove( null );
workbenchShell.redraw();
Shell shell = instance.getShell(); // desired window shell
shell.setActive();
shell.forceActive();
shell.setFocus();
shell.forceFocus();
shell.moveAbove( null );
shell.redraw();
}
Related
I have a JavaFX application that i have ported to Mac. When the application in foreground Command+H suppose to hide the application but for my ported application it is showing version details in a new popup windows.
I wanted to check if my program is suppose to handle Command+H and then hide the application or should it be handled by OS.
On macOS, it was solved by the following.
//
// Disable default popup window.
//
Desktop.getDesktop().setAboutHandler(null);
//
// Hides the stage when Command + H is pressed.
//
scene.getAccelerators().put(
new KeyCodeCombination(KeyCode.H, KeyCombination.META_DOWN), () -> {
primaryStage.setIconified(true);
}
);
I'm building a Plugin with the JCEF Framework for a Eclispe rcp. the Framework is written in C++ and has wrapper for Java. With the framework I get a browser in a Component
I have a curios Problem, which needs some steps to get there:
Click (set focus) to a random view in the rcp
Click in the browser
open another window (e.g. windows explorer)
click on the close button from the rcp
then a dialog box opens and ask if you want to close the program. The problem is that you cant click on yes or no, only if you click on another view again. The problem only occurs with my plugin.
I have added the Component to a Frame in the createPartControl methode:
public void createPartControl(final Composite parent) {
//create the browser
Composite composite = new Composite(parent, SWT.EMBEDDED);
Frame frame = SWT_AWT.new_Frame(composite);
frame.add(browser_component);
//do some other stuff
}
Do someone know what the problem could be?
If not, I thought about a workaround, that I will set the focus on my view from my code, if I click on the browser. I can create and add a FocusListener for the Browser.
My attempt:
//in the methode of the FocusListener
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("myview");
But it throws an Invalid thread access Exception
I am trying to catch SWT events, like SWT.activate, SWT.deactivate and SWT.dispose in Eclipse. So, I can see which dialog was opened or activated, which was closed and which was deactivated. If the event was caught, I extract the Shell object and extracts its title with shell.getText(). To listen to events, I used an untyped listener (edited):
PlatformUI.getWorkbench().getDisplay().addFilter(SWT.Activate, shellListener);
Listener shellListener = new Listener(){
#Override public void handleEvent(Event e) {
if (event.widget.getClass() == org.eclipse.swt.widgets.Shell.class){
Shell shell = (Shell) e.widget;
String shellTitle = shell.getText();
if (event.type == Activate) {
String message = "The following dialog was activated: " + shellTitle;
// do other stuff with 'message'
}
}
}
};
If in Eclipse I open 'New' and the listener above correctly displays 'New' as activated dialog. But if I select 'Java Interface' within the 'New' dialog, then I am landing in a dialog, called 'New Java Interface'. But my handleEvent method is not fired and therefore I cannot extract the new dialog title. My question is: What kind of event is called or what happens, when I am in an Eclipse dialog and clicking on something in it which leads me to another dialog (with a new title)?
I think the problem here comes from the fact that the New 'dialog' in Eclipse is actually a Wizard. When you select 'Java Interface' (in the 'New' dialog) you are actually then landing not in another dialog but on a page within the same wizard. Every page in this wizard can have it's own title but behind the scene it is the same underlying shell object, that is why you don't receive further events.
By the way: when working with the SWT.Activate, SWT.Deactivate and other similar shell events, it might be helpflul / easier to the a ShellAdapter
I inherited a Java app built (I believe) in Eclipse, which I'm modifying using NetBeans 7.4. I want to set the main menu title which shows up on a Mac next to the Apple menu. Right now that name is MainForm, but I want it to change dynamically to the contents of a specific text file (name.txt). I've looked up tons of info on project.properties, ANT scripts, and the like, but I can't find a definitive (and hopefully cross-platform) way to set this main menu title. I have a function in my code that returns this name, so I can use that if there's a place to do it. Thanks in advance!
I have found that in order to set the App Name in Mac OS X Application Menu, and avoid having it show up as the name of your Java project, you have to set it VERY early in the application cycle, using System.setProperty("apple.awt.application.name", "Your App Name");
Here's how I have mine set in my "main" java method that launches the application:
public static void main(String[] args) {
// the application menu for Mac OS X must be set very early in the cycle
String opSysName = System.getProperty("os.name").toLowerCase();
if (opSysName.contains("mac")) {
// to set the name of the app in the Mac App menu:
System.setProperty("apple.awt.application.name", "Your App Name");
//to show the menu bar at the top of the screen:
System.setProperty("apple.laf.useScreenMenuBar", "true");
// to show a more mac-like file dialog box
System.setProperty("apple.awt.fileDialogForDirectories", "true");
//underlying laf:
javax.swing.UIManager.getInstalledLookAndFeels();
// other set-up code goes here
}
else { // not on Mac OS X
// set-up code for non-Mac systems
}
java.awt.EventQueue.invokeLater(() -> {
// run the program
});
}
I am developing the network application in which I want to run my J2ME MIDP application in background without any GUI so that is any way to construct the application is such manner.
try this
set your current Display to null. so there will not be any form or alert running on the screen. But however your code will be running in the background.
Display display = Display.getDisplay(this); // here 'this' points to Midlet
display.setCurrent(null);
it easy just have a code of line on any event for example in the click of button
Display.getDisplay (this).setCurrent (null);
and return back the control via
Display.getDisplay (this).setCurrent (mycanvas);
Yes this code works Good,
display = Display.getDisplay(this);
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void hide()
{
Display.getDisplay (this).setCurrent (null);
}
This is will work like, make a button can after clicking it call hide Function, or you call this hide function in constructor so it will hide itself when app start, can you keep unHide statement in appStart() so if you Tab the program then it will unHide app again.
NOTE: you said you are working on Network app, but some mobile will turn off the Internet Connection, when the Mobile screen Turn Off. please check this. and If you found any solution It will be Good to share here.