How to add any Component in the JFrame TitleBar - swing

How to add any Component like a JButton on the JFrame TitleBar in java swing.

I assume by "title bar" you think of the header with the window menu button, document or program title and buttons for (typical) maximize, minimize, close.
The window borders are drawn by the operating system (whatever part, e.g. with XServer it would be a window manager most of the time) - usually. And this is what the user wants - usually. Then this part of the window is outside the reach of Swing, you need to add components by native code (JNI or one of its nicer wrappers like JNA).
But you can set a Frame to undecorated via setUndecorated. This leaves the whole window area in your responsibility, you have to draw everything yourself and care for things like draggability of the window. Think of a completely "skinned" application. If the look and feel you use supports drawing of the windows borders (javax.swing.LookAndFeel#getSupportsWindowDecorations()) you don't have to do this yourself but set JFrame.setDefaultLookAndFeelDecorated(), the LookAndFeel will draw the border with Swing components. Then you can add Swing components either by glasspane or by changing the component that draws the title bar.

Related

image in clojure

I made a frame give a title to it and I added buttons to the frame using clojure. I am not able to guess how to add background image to my frame.
I have a background image stored in the drive, I tried adding the background image in doto panel but it showed series of errors.
Help!
You need to go a little bit more deep than that. paintComponent of JPanel is your entry point. Inside paintComponent you can load the image in draw it.
After that, you call getContentPane().add(new YourJPanel()) of your JFrame.
One a side note. If you are planning to do Swing development in Clojure, did you consider: Seesaw?

how to give drop shadow for adobe air window?

I am developing adobe air application.
I am trying to give drop shadow around window in WindowedApplication skin class, But it is not taking the shadow.
I want to give shawdow behind window as seen in Microsoft link application.
Any suggestion or solution are welcome
Thanks
Set none and true in your app descriptor XML to get a transparent and chromeless native window.
Then you would have to add any window decorations you might need back, and add the drop shadow to the top most parent sprite of your window (probably also making the parent sprite's origin and size inset within the native window to account for the drop shadow area).
You can try this example as well

Adobe Air: Can you draw something outside of a window?

For example, how would I draw an image outside of my window area, anywhere on the screen?
It is not possible to draw outside your window. You can however simulate that effect by creating a maximized transparent window and then drawing on it so that it seems you are drawing at arbitrary points on the screen. You will face issues like the visible windows below the transparent window will be inactive till you minimize the transparent window.
You can also create a new window inside your application and place it somewhere on the screen. If you set systemChrome to none it will not have any menu bars and will appear if there is nothing on the screen unless you fill it.
See http://livedocs.adobe.com/flex/3/html/help.html?content=WorkingWithWindows_1.html for more information about windows.
A tutorial to spawn new windows without any menu bars and outlining is here : http://www.adobe.com/devnet/air/flex/quickstart/articles/creating_toast-style_windows.html

How do I force or lock focus in actionscript 3?

I want to create a dialog or alert box, where a DisplayObject would take and force the focus, until an okay button or something releases the lock. thanks.
The easy way to do this is to make your "dialog" as big as the stage, with a whacking great transparent area around the dialog itself.
The transparent area can listen for any mouse clicks, and just swallow them (which will prevent them being picked up by stuff further back in the display list).
To show the alert, just stick it on top of everything else, When the user closes it, take it away again.
If you are using flex and actionscript, simply use a SkinnablePopUpContainer
var alt:CustomPopUp = new CustomPopUp();
alt.open(this,true) //the second variable is for modal, which will disable view
this.enabled = false; //this will grey out the parent view and provide visual focus to your popup.
To do this, you will need to disable access to all objects under your 'alert' DisplayObject. There are multiple ways of doing this, here 2 I can think off:
Loop through the display list and disable any display objects under your alert depth wise.
Cheat it with a blocker. When you display your alert, display another clip (could have alpha set to 0 ) that blocks the user from hovering/clicking objects. The blocker might need a bit of setup( buttonMode = true, useHandCursor = false, etc. )
This 'modal' behavior has been around for some so there might be no need to reinvent the wheel, depending of your current setup.
If you're using the Flex framework, you've got the functionality in, for Flash you can use the Alert Manager from the Yahoo! Flash Astra Components:
Goodluck,

How to animate showing of JPopupMenu?

I'd like to show increasingly more of a JPopupMenu so it appears to "slide out". It's not for menu items, where animation doesn't make too much sense. Instead it's for a panel with some real components (oh yeah, you can add any JComponent to JPopupMenu).
JPopupMenu has many private fields and methods, which makes it hard to extend. Plus I'm not familiar with Swing animation to begin with.
Thanks a lot for your help!
I just did this within the last few weeks. I went a slightly different approach, and Grabbed the layeredPane, and then added a Custom JPanel to the layered pane. In the jpanel i overrode the getHeight method, and had the height start at 0. I could then add whatever components I wanted to my jpanel. In the jpanel I had a method to start animation, this started a timer, and in the timer all I did was increase the height of my jpanel to a max size.
That's it. It works really well in my application, I have it tied to expand below a Jbutton on press, and collapse on another press.
One more thing, you'll want to add a mouseAdapther to the jpanel so events don't go through the components below the layer.