I am making a Java application, until I realized that Java doesn't use the Genuine Windows dialog layout.
I used this to set the UI layout to the system default (in this case, Windows):
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
I realized that dialogs created using this look and feel is different from Windows default.
Compare these two dialogs (first is Windows, second is Java):
Am I wrong, or is there a way?
Doesn't look like OP is on SO anymore, but regardless, if your goal is to create an application with the same look and feel as native applications, you might consider using Eclipse SWT.
To achieve nearly the same look and feel as the top image, you can use the SWT MessageBox.
For example:
final MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_WARNING);
box.setText("Rename");
box.setMessage("If you change a file name extension, the file might become unusable.\n\nAre you sure you want to change it?");
box.open();
will create:
I'm not aware of a way to remove the X cancel button, but there may be a way.
Related
I'm using the 3dmod program of IMOD which is coded in Java (using Qt I think). For my project, I often need to open multiple .mrc files (3D reconstruct) as well as the model I've put on it using a command like the following:
3dmod -E 1U my_3d_object_part1.mrc my_model_part1.mod
After doing all the parts (around 5-10), I need to open all of them to compare.
Are there any ways to create a shell script to do this? Knowing that file names are almost identical, only the number 1 will have to change.
Note that the doc says "3dmod will accept some Qt options (such as -style)". I don't know what those options do or if they can control the window position at launch. I am hoping I could distribute my model windows across my screen to see them all at once.
I am concerned this may not be possible. Are there any ways to control the initial window position at opening?
Qt5 applications can set their initial size/position using the qwindowgeometry flag, like this:
./myApp -qwindowgeometry 640x480+50+50
EDIT:
On Qt4, and I think only if you're using X11, the flag is named -geometry.
In my Java application I have a window which holds a JTextArea within a JScrollPane with scrollbars policies set to AS_NEEDED.
As I run my application I see that JTextArea this way:
Why am I seeing the scrollbars with that cutaway knob (which doesn't reflect a "standard" representation like this)?
The Layout for the frame is GridBagLayout, and I'm on Mac OS X 10.8.2, should that matter.
This is based on the Look and Feel your app is using, and the limitations of Java's integration with the native OS layout components. The one in your screenshot looks like Nimbus.
Swing applications always custom-render the look and feel, and don't do a very good job of using the native OS widgets everywhere. The result is that you get weird looks that might be consistent the OS only some of the time, or only with certain layout components.
Welcome to developing cross-platform desktop apps in Java. :(
To attempt to get the system look and feel when your application starts you can do this:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassname());
} catch (Exception e) {
// Handle exception
}
This will set the look and feel to that of the system regardless of what you run it on.
And as mentioned, the default look and feel for your application appears to be Nimbus and not OSX's Aqua, which again can be fixed with he above snippet and you could (should you care to) offer a UI option to the user to change the look and feel of the application to whatever they chose.
You are with Nimbus LookAndFeel
http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html
Is there a way to make sure that a user cannot close or leave my Swing application? I've tried to make it fullscreen, but you can still Alt-Tab away from it—and besides, that doesn't work well when you decide to use JOptionPane's dialogs.
So, is there any way to make a user use only this one Java program on a device?
Edit: Some people wonder about the purpose. The application is supposed to be sorta "embedded" into the handheld device (which runs under Windows), so the users of the device will use it as we intend it to be used—for example, that they won't play Freecells or do something worse instead of doing the actual work. Have you seen ticketing kiosks? They are locked down pretty well, you can't just close their big flashy GUI and get to the Windows desktop!
Okay #Daniel showed you how to make a Java app un-closeable (+1 to him) by calling:
JFrame#setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
on the JFrame instance.
To make sure you cant leave it i.e by pressing CTRL+ALT+DEL and ALT+TAB etc you may want to do this (applies to windows only):
1) Disable TaskManager/CTRL+ALT+DEL by:
Setting registry key:
HKCU/Software/Microsoft/Windows/CurrentVersion/Policies/System/DisableTaskMgr = 1
via reg script or cmd.exe.
2) To disable all shortcuts together like ALT+TAB etc see here (Download/use the *.reg script and execute it via cmd).
Uncloseable yes, you can use setDefaultCloseOperation(); and pass it JFrame.DO_NOTHING_ON_CLOSE
Example:
import javax.swing.*;
import java.awt.*;
class app extends JFrame {
app(String title, int height, int width)
{
super (title);
setSize(width, height);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setVisible(true);
}
}
class program {
public static void main(String[] args) {
app myApp = new app("Hello", 350, 750);
}
}
We do something similar with a POS application, but we cheat a little bit. While making use of Full Screen helps a lot, we found users could STILL exit the application.
In the end, we created a Windows Service (yes, we run on Windows) that automatically RESTARTS as soon as it's closed. So, you can see the Windows desktop (we removed the icons) for a split second, but then the app pops up again. The benefit of this is also that we can update the JAR file remotely, from the intranet, and all the users need to do is push a button that closes the system, it restarts automatically and is updated. We wanted to use WebStart, but had problems integrating it with our wrapper.
The wrapper itself is a Python application that just starts the JVM and application, compiled to an EXE. Simple, but effective.
The net effect is a closable application that will automatically start itself again. Good enough for our use where we need to user to be able to do one thing and one thing only. Giving the startup credentials for the application Admin privileges, and the users just a normal account, took care of the pesky 'alt-ctrl-del' users as well. You can't kill a process that's got higher access rights than yourself.
If you don't feel like writing your own wrapper, give http://wrapper.tanukisoftware.com/doc/english/product-overview.html a whirl, it looks like a brilliant product.
You can catch pretty much any keystrokes you like (and have them ignored) in your app, so Alt-Tab can be fixed. The one key combination that an application can never (ish) handle itself, is the Ctrl+Alt+Delete, which is hooked into the kernel in many operating systems for security reasons. As a side note: this is why many login screens ask you to hit C+A+D before entering your username and password.
You can make a maximized window that can't be unmaximized or closed. You'd also have to trap certain keystrokes such as CTRL+SHIFT+ESCAPE, ALT+TAB, WIN+[anything], various Fn keys, and you'd have to do something to prevent CTRL+ALT+DELETE from working (Either from showing the task manager or from bringing up the blue options screen in windows vista or 7.
I believe there are windows API calls that can change the behavior of CTRL+ALT+DELETE somehow but have no idea what they are. A good place to investigate would be Sysinternals Process Explorer, which has the functionality to replace the task manager. Figure out how it does this, then replicate it.
Is it possible in Delphi to keep a window on top of all other windows? For example when you have an error message in your application, let's say you want to keep the window on top and make sure the user has to click something before he can do anything else. And I really mean anything, like clicking another program in the background. And how about in Java?
No. Raymond Chen of Microsoft has a great article about why not here. The gist of it is that no matter how hard you try to keep your window on top, someone else can always come along and do the same thing.
You could do this in the old days. It was called a system modal dialog and you used the now obsolete SetSysModalWindow() function.
They were utterly repugnant and so sense and order was restored when Windows NT based versions of Windows took over.
In Delphi you can do FormStyle:=fsStayOnTop;. This will put you in front of all normal windows.
But if there are other windows which have that style set too(such as the task-bar) those might be on in front of yours. In particular among those windows the one that has focus is has the highest priority.
You can try to ensure that your window always has focus, but that's rarely a good idea. And you will incur the wraith of Raymond.
You can also use a layered window. I think those are in front of normal always-on-top windows. But this has severe side effects and is most likely not the correct choice for you.
When I start my SWT Application from Eclipse, the Shell always starts up in the background, with the IDE in front of it.
I tried everything, like setting the focus, activating the shell, etc.
Did someone else experience the same behaviour and maybe even solved it?
When you activate a Shell (usually via the open() method), SWT asks the window manager on your given platform to make the shell active. However, depending on the window manager, the shell might not become the top-most shell on the desktop. Here's an article with some interesting info about opening shells (see section "11.4.6 Opening a Shell").
If this is the cause of your issue, you may be able to use the forceActive() method of the Shell class to force the shell to become active. However, depending on your application, you may not want to adopt this approach. The following is a warning from the article:
Most Programs Should Never Need to Use
forceActive()
Forcing a shell to be active should be
reserved for those occasions when you
must get the attention of the user
(which is almost never). After all, do
you like it when another window steals
your keystrokes?
Double check your manifest to see if you're missing anything. That is to say if you are doing this via Eclipse RCP