Keep window on top in Delphi or Java - java

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.

Related

Start external program, but keep application in foreground

I'm writing an RSS reader desktop application in Java with Swing (odd choice, I know) that needs to start the web browser of the user's choice (suppose it's Firefox). I use runtime.exec("firefox -new-window $url"). This starts a new window of Firefox which appears in the foreground.
When I click a link in the application, I want to start Firefox but keep my application on the top (so I can open several links and then go back to them). Is there a way to do this? Preferably it should work with any browser (any program) and start it maximized but not in the foreground, though I'd settle for other solutions like starting minimized or using some command line arguments of Firefox (I haven't found any for this purpose).
It's kind of funny - all the questions about this I've found is people having the opposite problem, and also I've written a similar application several years back in C# which works as intended. I vaguely remember having the same problem, but looking at the sources now, I don't see what was the solution - it seems like it simply starts the browser with no extra stuff.
I got it. The reason why I could not find the right answer was that I was asking the wrong question. The solution has actually nothing to do with launching programs. All that is necessary is to set .setAlwaysOnTop(true); on the main JFrame.

Corrupted (cached?) fonts in java swing

My machine seems to be experiencing some weird issues with java swing.
This sort of thing happens with other programs as well but the corruption goes away with scrolling or highlighting the text. What could be causing this and why doesn't java go the same? All the characters seem to be cached so that when a character gets corrupted, all of the characters of the same type have the same corruption (not true of anything but java swing).
I have been googling around for this sort of issue but most of them only suggest issues with graphics drivers and settings for windows... (I am running kubuntu)
Side note: Sorry if this doesn't belong here. Didn't really know where else to ask.
Among the many possible causes,
Verify that all correctly synchronized Java Swing programs using standard font families with the default Look & Feel exhibit this behavior; if not, it may very well be a driver problem.
Investigate whether the Ubuntu video driver permits alterations similar to the one required in this Windows case.
Try a different window manager.
Try a different Look & Feel.

a program, running on the background (JAVA)

i want to write a clock program, that should run at background and broadcast the current time according to the system if the keys "1" and "2" are pressed together. i already have a program itself (including audiofiles and appendings) so everything i need, is to find the way to make the program window inactive, but to do it in such way that it will activate when the keys are pressed. what can i do?
On Linux with KDE you can use khotkeys to set up a keyboard hotkey which will send e.g. a dbus message to your program to tell it to reactivate. I don't know if 1 and 2 together is an allowable hotkey - it doesn't make much sense because it will likely cause a 1 or 2 to be inputted into the program you are currently using, which may or may not do anything but it's better to use a key like ctrl, alt or the windows key to avoid that problem.
In other environments / operating systems there may be something similar to khotkeys, I don't know.
I dont think Java can help you here - you're looking at something like a TSR, which unfortunately is not a Java thing. They went the way of the dinosaurs anyway, along with MSDOS.
You've to go native for something like this on the modern operating systems.

Is it the most common case?

Why when I click on the x button to close the window in a Java application only the window dissapears and the applicaton is still running.
I've read so many times that java designers tried to cater Java behaviour for the most common needs of programmers and save they precious time and so on and so on. What's more common case than closing app when I click on a X button?
Whatever the reason is, it really doesn't matter as long as you're aware of how it works and how to make your program behave the way you want.
At a guess though: One app can have several windows, exiting the app when one of them is closed doesn't sound very smart. Keeping track of how many windows are open/closed/hidden/not yet shown and so fort to be able to exit when the last windows is closed might have been too much work/too many edge cases etc. Thus it's up to us, programmers, when we want our app to exit.
In any case, if you want your app to exit when a window(JFrame) is closed, you can just tell it to do so:
myJFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Many applications have more than one window open at a time and closing a single window should definitely not shut down the whole application.
Also, most application want to do a bit more than a simple System.exit(0); when the quit. They might want to ask the user to save some files (or save them automatically), they might want to clean up some temporary files or notify some remote host of their shutdown or something like that.
In effect it's very unlikely that the only effect of closing a window is ending the JVM.
myJFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Dispose is almost always preferred. If you explicitly say EXIT_ON_CLOSE and you ever want to display more than a single window, you will need to modify your code to use DISPOSE_ON_CLOSE instead. Not a huge deal, of course, just seems a better choice.
In my opinion, the DISPOSE_ON_CLOSE should have been the default, not HIDE_ON_CLOSE. Oh well, that's what we've got. EXIT_ON_CLOSE should probably be avoided for the same reason that calling System.exit(0) should be avoided in a window listener (though there's nothing wrong with it per se, it's just not very future flexible).
Even better, it's almost always preferred to attach a WindowListener to your frame and set the default close to JFrame.DO_NOTHING_ON_CLOSE. This way, you control when your application shuts down, including a prompt to the user to save any work, etc.

What's ideal debugging setup? window placement etc

I am interested in knowing Debugging setup that'll allow a programmer to be most productive. Assuming knowledge about debugging in general.
I am mainly interested in knowing how and where you place different windows like the variables window, code window, the stack. Also possibly the relative size of different windows.
I'd prefer if there are screenshots attached and a description of why the setup works for you or one that is efficient.
I mainly use Eclipse and Netbeans.
Most productive? That's going to vary greatly from person to person. You shouldn't focus on what works best for other people or details like precise window placement... figure out what works best for you with some trial and error.
For me, multiple monitors are important. I keep code and tools (Eclipse, SQL manager, etc) open on one, and use the other for the console and the running program (whatever it may be: website, windowed application, etc).
First you have to know how to use the debugger really well and then after that the placement of windows is just frivolous detail, for the most part. It will just fall into place without having to mimic other people's comfort level with the tools.
It sounds like you're looking for a static setup but likely you will show/hide windows depending on what you're debugging and size them to different situations. At least that's what I do. So I would post many screenshots and they'd all look different.
"I'd prefer if there are screenshots attached and a description of why the setup works for you. "
You're exactly right knowing it works for the other person.
In addition to what others have said, one thing that I do with respect to variable windows - Visual Studio gives you 4 different watch windows. I usually put them all into a single tabbed window, and each tab will represent a different programming context. For example, tab 1 will list variables that I usually need to look at when dealing with area A, tab 2 has variables for area B and so on.
Doing this, I find that the watch windows don't get over cluttered and I spend less time setting up variables

Categories