I need to make a custom ui which looks like the following image :-
I know how to change the button to that arrow shape and everything else.But I can't understand how to move those close ,restore and minimize buttons to the center and give them round shape (on Windows).
On Googling ,I found how to make custom shape windows but it doesn't meet my requirements.
Can anyone please tell me how to do this or any link.??
You will need to create your own title bar as another panel with buttons and then remove the window decoration on the frame.
JFrame frame = new JFrame(...);
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//This will close the frame and exit
To minimize and maximize, listen for button events and use:
frame.setState(Frame.ICONIFIED);//minimizes
frame.setState(Frame.NORMAL);//restores
See Frame.setState(int) for details.
Related
I am working on a Java desktop application using javax.swing.
I want make my application border-less and at the same time resizeable.
When I remove the border using the frame.setUndecorated(true); method I can no longer resize the frame using mouse clicks and drags.
How can I hide the border of the frame and still let the user resize it?
Frames allow a user to interact with the JFrame using their mouse. If you remove the frame then you cannot use it to move or resize the frame. You can reimplement this functionality yourself (not sure why you'd want to but of course experimenting is always fun!).
First you must somehow get user mouse events. By creating a custom JComponent, maybe called ResizeGrip, and placing it in the bottom right of your frame you can visually show your user that they can still resize the frame. You can then implement a MouseListener to see when the user has clicked and dragged your ResizeGrip.
Then you need to turn those event detections into instructions to resize the frame pragmatically, that is via someJFrame.setSize(newWidth, newHeight);. You will also need to do something similar if you want to move the frame.
Check out Resizing Component for a general purpose class that will allow you to resize any component.
The class is a MouseListener that installs itself on the components you specify.
The basic code to add it to your frame would be:
JFrame frame = new JFrame("SSCCE");
frame.setUndecorated(true);
ComponentResizer cr = new ComponentResizer();
cr.registerComponent(frame);
You can control which sides can be dragged by specifying the "drag insets". The default value is 5 for all sides which means you can resize any size. You could limit the frame to be resized only horizontally by using:
cr.setDragInsets( new Insets(0, 0, 0, 5) );
I want to add the new button with an icon of a question mark to the left of buttons "maximize", "hide" and "close". how to make it (like in a pic)?
You need to create a custom RootPane/TitleBar.
This means you need to set your JFrame to undecorated and then set your custom instance of what extends RootPane to your JFrame
It is hard to change native Title bar, because it is originating from the operating system. But you can remove native Title-bar setUndecorated(true); and create your own Title-bar , See simple tutorial here
OR
You can see an another way in Substance look-and-feel
I have an opened an image using JFrame in java. Now I want to display a button at particular location in that image to do certain task. But i feel it to be more challenging. Please give me an idea or source code to do my task.
waiting for valuable reply
You can make a JComponent and use a MouseListener to see if the user clicks in the area of the image. Thus you can execute your action if the user clicks.
Look at the LayeredPane layout manager. This will easily overlay a button on a picture.
Why don't you try to just add a click the image to run the command you want just like button use mouse listener. or just prompt a JOption pane for options for the Image?
I want to make a JFrame with the drawn shadow.
I made a undecorated window and made a background with shadow(grey) and empty part(green),and it can be dragged.
The problem is,when I try to drag the shadow or the empty part,the frame can also be dragged!
I want to bring the window under the window(Another application) that was under it,just like I click on the window.
I tried setBack(),but it just put it under every window,not the back one.
How to click through the window?
I am unable to understand your question clearly.
In case want a frame within a frame, then opt for JInternalFrame class.
I have an open-source java swing application like this:
http://i47.tinypic.com/dff4f7.jpg
You can see in the screenshot, there is a JPanel divided into two area, left and right area. The left area has many text links. When I click the SLA Criteria link, it will pop-up the SLA Criteria window. The pop-up window is JFrame object.
Now, I'm trying to put the pop-up window into right area of the JPanel, so that means no pop-up window anymore, i.e. when I click the SLA Criteria link, its contents will be displayed at the right area of the JPanel. The existing content of the right area of JPanel will not be used anymore. The concept is just same like in the java api documentation page: http://docs.oracle.com/javase/6/docs/api. You click the link in the left frame, you'll get the content displayed at the right frame.
The example illustration is like this:
(note: it's made and edited using image editor, this is not a real screenshot of working application)
http://i48.tinypic.com/5vrxaa.jpg
So, I would like to know is there a way to put JFrame into JPanel?
I'm thinking of using JInternalFrame, is it possible? Or is there another way?
UPDATE:
Source code:
http://pastebin.com/tiqRbWP8 (VTreePanel.java, this is the panel with left & right area divisions)
http://pastebin.com/330z3yuT (CPanel.java, this is the superclass of VTreePanel and also subclass from JPanel)
http://pastebin.com/MkNsbtjh (AWindow.java, this is the pop-up window)
http://pastebin.com/2rsppQeE (CFrame.java, this is the superclass of AWindow and also subclass from JFrame)
Instead of trying to embed the frame, you want to embed the frame's content.
There is (at least) one issue I can see with this.
The menu bar is controlled by the frame's RootPane.
Create you're self a new JPanel. Set it's layout to BorderLayout.
Get the menu bar from the frame (using JFrame#getJMenuBar) and added to the north position of you new panel.
Get the frames ContentPane and add it to the center position of the panel.
There is undoubtedly countless other, application specific issues you will run into trying to do this...
No, you don't want to "put a JFrame into a JPanel" and your illustration above doesn't demonstrate this either. Instead it's showing a subordinate window on top of (not inside of) another window. If you absolutely need to display a new subordinate window, I'd recommend that you create and display a JDialog. The tutorials will explain how to do this, or if you get stuck post your code attempt and we'll help you work with this.
Edit 1
You state:
I need to convert from the pop-up window style into the jpanel content style. It's just like the java api documentation page style: docs.oracle.com/javase/6/docs/api When you click the text in left frame, it doesn't show any pop-up, right? The content is displayed at right frame directly. So that's basicly my goal. The source code is quite big. I will try to paste the source code if possible.
What you are looking for is to simply implement a MouseListener in a JList or JTable, and when responding to the click get the content based on the selection made. This has nothing to do with placing a JFrame in a JPanel and all to do with writing the correct program logic. Again, display it in a modal JDialog -- but that's all secondary to your writing the correct non-GUI logic. You're really barking up the wrong tree here. Forget about JFrames, forget about JPanels for the moment and instead concentrate on how you're going to extract the SLA Criteria data when it is clicked on.
Edit 2
I think I see what you're trying to do -- instead of JFrames and JDialogs, use JPanels and swap them using a CardLayout which would allow you to swap views.
I had skimming the source codes, I saw that the AWindow.java has internal panel (APanel.java) to hold the window's content, and it also has a public method to return the content panel object (getAPanel()). With this, I can use it for fetching the window's contents into other container.
Finally, I decided to use JTabbedPane in the right area of VTreePanel for displaying the pop-up window's contents.
You cannot put a Jframe into a JPanel. Instead you should try to create a separate panel that has functionalities like your JFrame and embed that into your JPanel.
Since you can put a JPanel into another JPanel but not a JFrame into another JPanel