Custom Java Window Title Bar Menu - java

I'm trying to allow the user to change the title of a window in Java without adding components to the window itself. I'm actually trying this with a JInternalFrame, but figure the solution should be similar for a JFrame. I simply want to add an additional menu item in the context menu that pops up when right clicking on a window title bar. For example, the Set title below:
This example is on Windows XP, but perhaps there's a way to get the window context menu OS independently perhaps similar to the SystemTray.getSystemTray() (but for individual windows within an application). From this I would be able to provide my own ActionListener to popup a dialog for the user to enter a new title.
Is this a much bigger task than I'm guessing it is? Does anyone have solutions they've used before?

Short answer: I don't think this is easy. I'm not 100% sure if it is possible.
First, JFrame and JInternalFrame are actually quite different. JFrame is a top level component whose title bar and such are typically provided by the OS. JInternalFrame's entire content (including title bar) is provided by the Swing LAF.
For a JInternalFrame, the context menu is provided by the LAF, not JInternalFrame itself. You would have to do something with the UIComponent in order to change the context menu. I think you would likely have to provide a custom UI component in order to do this, which is ugly and typically breaks across different LAFs or works but looks terrible at best. See BasicInternalFrameTitlePane, the createSystemMenu method.

I don't think this is possible without digging way too deep into Swing's internal UI system and I wouldn't even consider doing this. Why don't you use the inbuilt JMenuBar of JInternalFrame?
myInternalFrame.setJMenuBar(myMenuBar);

Related

Java Swing Exit Icon?

I was wondering how to change the minimize, maximize, and exit button icons in the top left of the default JFrame swing window? I've looked everywhere and can't find a tutorial or method that does it.
Minimize, maximize/restore and close buttons are bound to the frame decoration used.
If you are using a frame decorated by system (for example some Aero frame in Windows 7) - you cannot modify those buttons since the whole frame decoration is provided by system and there is no good way to invtervene and change its behavior.
On the other hand - if you are using a custom Look and Feel (shorty - L&F) written on Java and it provides its own frame decoration - it is possible to modify it if you have access to that L&F sources or if that L&F provides some options to add/remove those buttons.
You can read more about L&F here:
http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel
You can also find a lot of links to custom L&Fs here:
Java Look and Feel (L&F)
Start with JFrame.setDefaultLookAndFeelDecorated(true).
Then set the Pluggable Look and Feel.
For best results, this is most reliably done before the first GUI element is visible on screen.
See How to Make Frames - Specifying Window Decorations for more info.
As far as I know, you cannot, but if this is something you need to have done, you can use Netbeans to use JavaFX, which allows you to fully customize the window, including the buttons like that. The window doesnt even need to have these buttons.

How to make the desktop pane that Netbeans has

So when I start up Netbeans, they create a little panel on the desktop for showing the progress of loading. I'm pretty sure Microsoft Office 2010 uses this too. I was curious how to make one of those in java?
I looked through the API and saw JDesktopPane. But I don't think that's what I'm looking for unless you can take that and put in on the actual desktop, but I'm unsure. Thanks in advance!
you can actually do it using JPanel.. you don't need to do anything else..no need of desktop pane
all you need to do is design a JPanel and put a progress bar inside it that will link to a process and show how much it has been completed.
JPanel doesn't have normal frame functionality like minimize, Close etc and will act exactly as you are trying to make up.
Update : Just tried doing what you wanted.
You need to start working on JFrame. and set its decoration to false.
in Netbeans, you can just go to Frame properties and set Undecorated to true
or inside code you can just write setUndecorated(true);
then you have to design your frame, put a progress bar inside it, link it to a function, set its onTop value to true (which means it will always be on top) and set its position to center of screen. done!! you are ready with your window!!

Small Window Over Components

I already look at java library and dont know what to use to do this..
I already tryed JInternalFrame but thats not what I really want.. because it needs to be added to a JDesktopPanel right??
And in my program I have a JFrame with content pane using BorderLayout..
Then on borderlayout center I have a JTextArea, on borderlayout east I have a list.. and on borderlayout south I have a JPanel..
What I want is, when I do a certain action, it will pop up a "mini window" where I need to choose something.. u see?
and if I create JDesktopLane it will overlap what I have on the container..
the window will be made by my like a color chooser pallete , like a grid with colors.. and a label on top saying some text..
I just dont know how to make a "window" over the other components, and users can still drag over the frame, and interact with all the other components.. the jtextarea and such..
I guess you understood, thanks alot in advance!!
If u dont understand something please tell me, I really want to do this :)
Just dont know what to use..
Thanks again ;)
Have you tried JDialog?
It's because Jdialog are not component to be add in a JFrame, it's an independant thing running on it's own
if you use JDialog, the construct parameter parent indicate wich frame the JDialog is related to.
The typical class for this task is JWindow, a borderless top-level window that can be freely positioned. You could use SwingUtilities.getPointFromComponent to get the screen coordinates for a realized coordinate.
Top-level windows (JFrame, JDialog, JWindow) are not added to containers. They can get other windows as parent.
I dont want to use another JFrame.. that is kinda bad for code, its a small window with a simple function..
Structure your code so you can read it, others can read it, and you can debug it easily (the latter is a result from the first). A low class count is useless and -most of the time- contraproductive.
Why should another JFrame (or other window) be bad?
If you absolutely want to avoid opening top level windows (e.g. to avoid applet warning icons or to implement a special kind of user interface) you could use a JLayeredPane to add additional JPanels above your existing GUI elements.

How to use a custom icon with a system tray baloon notification/tooltip using SWT?

I was wondering whether SWT/jface allow for specifying a custom icon (other than predefined SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING) for the application system tray item balloon tooltip? I would like to do something like:
ToolTip tip = new ToolTip(shell, SWT.BALLOON);
tip.setText("Notification from a tray item");
tip.setMessage("Here is a message for the user.");
tip.setIcon("/path/to/custom/icon");
trayItem.setToolTip(tip);
I am aware that ToolTip clas does not have the setIcon() method. Is there any other way to achieve this? This would be very useful for application level notifications, etc. Thanks!
This article might help you SWT: Tray Icons and Tooltips.
EDIT
It's not possible, those images are obtained from OS, and cannot be replaced. The setImage() method which are you calling is one of the Tooltip parent's method and the image is completely ignored by Tooltip class.
See source codes for Tooltip SWT class and check the public void setVisible (boolean visible) method (almost at the end), there you can see where are those image icons obtained.
It might be nice feature request for SWT team.
EDIT2
Article about Custom Tooltip in Eclipse 3.1 RCP applications might answer your question. He uses Custom SWT controls from Novocode toolkit, check the BalloonWindow (A Shell wrapper which creates balloon popup windows).

Resizing JPopupMenu and avoiding a "flicker" issue

I am trying to implement a search results popup list similar to the style found here:
http://www.inquisitorx.com/
(I'm not trying to implement a Google search, I'm just using this as a rough example of the style I'm working on.)
In any event, I am implementing this by using a JList contained within a JPopupMenu which is popped up underneath a JTextField.
When a user enters search terms, the list changes to reflect different matching results. I then call pack on the JPopupMenu to resize it.
This works, however, it creates a slight flicker effect since it is actually hiding the popup and showing a popup. (See the private method getPopup in JPopupMenu where it explicitly does this.)
Is there any way to just get it to just resize itself (aside from using a JWindow)?
to me work :
popup.pack();
popup.validate();
this work in linux with java version "1.6.0_34". I don't know is that work on windows.
The setSize() method didn't work in my case. The popup.pack() approach did work, but also resulted in a flicker. The best solution that I have found was the one found here. In short:
Window window = SwingUtilities.getWindowAncestor(popupMenu);
window.pack();
window.validate();
Have you tried setSize()? It looks like that gets handled in JComponent and might avoid the repaint issues.
I think the issue that getPopup is addressing is what to do when the dimensions of the popup will not fit within the window. When that happens, it drops back from a lightweight component to a heavyweight and that definitely requires a hide and show. So, I think if you can guarantee your popup won't extend beyond the window the setSize might do the trick.

Categories

Resources