Internal JFrame Properties - java

I have a JInternalFrame as shown below.
Are there properties that allow for?
coloring
hiding the title bar
adding text
Further Customization*
to the top bar?
The only thing I have been able to find is:
jInternalFrame1.setTitle("Hello");
But I am more after a way to hide it etc.

you can set through it's constructor like button maximize, minimize, resize, icon etc
and http://www.roseindia.net/answers/viewqa/Java-Beginners/1923-Hide/remove-titlebar-of-JInternalframe.html
another example with multiple JInternalFrame

To remove all the decorations from the title bar you can create a smaller bar (in height) that will only allow the user to drag the internal frame:
frame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
To remove the title bar when using the Metal LAF you can use something like:
BasicInternalFrameUI ui = (BasicInternalFrameUI)frame.getUI();
Component north = ui.getNorthPane();
north.setPreferredSize( new Dimension(0, 0) );
north.validate();

Related

how to edit jframe title bar?

jframe title bar image (run time)
I don't want it undecorated, want black color and change icons.
I am making my college project, I tried making a customized title bar with an undecorated frame, and it works fine, but I have problems dragging the frame and re-sizing it. So I thought maybe I could edit the original frame but didn't find any solutions. Can someone guide me through this?
Assumption : You need a by-default decorated JFrame, which acquires the look & feel of the machine's operating system.
Setting an icon and customizing text on Title bar is easy.It can be done as shown below,
class TitleBar {
TitleBar(){
Frame f=new Frame();
//Setting TitleBar icon with "YourImage.png"
f.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("YourImage.png")));
//set other parameters as per your choice viz size layout etc.
//Set the Title Bar text
f.setTitle("YOUR CUSTOM TEXT");
f.setVisible(true);
}
Now with the frame decoration turned "ON", it is not possible to change the color of titlebar, font of the top-level JFrame (to the best of my knowledge). You CAN change the color of an InternalFrame however.
If you want to customise these then turn off windows decorations with f.setUndecorated(true) and you can change the title bar appearance with the help of LAF (Look And Feel). This is better explained in the answer below :
Change the color of the title bar in javax.swing
You may also try modifying the UIDefaults as shown here :
Modifying UIDefaults | For Windows 10 and above
Do upvote if my answer is useful !!

How to change the default JFrame Window color?

I am building an app for Windows using Java Swing/AWT interfaces in IntelliJ Idea. I am using a default JFrame to display my application GUI. However, I would like to change the default frame outline (window) colour to either transparent or custom colour.
Here is what I am trying to achieve:
This is the window I have:
These two are the ones I am trying to achieve (transparency or custom colours):
Or this
Is there a way to achieve this?
You can use custom title bar by creating a new panel and set undecorated on your frame to hide default title bar
add your title to the new panel and buttons (exit, minimize...)
Frame.setUndecorated(true);

Is there a better way to lock the main scroll bar without hiding it in GWT?

I set my body element to
body {
overflow-y: scroll;
}
This creates a scroll bar on my body element. When I create a scrollbar and scroll to the bottom the main area of my page is also scrolled.
I found some posts on this topic: Prevent scrolling of parent element? prevent Scroll "bubbling" from element to window but these are not applicable for GWT.
I tried the following:
#UiHandler("panel")
void onPanelMouseOver(MouseOverEvent event) {
Window.enableScrolling(false);
}
#UiHandler("panel")
void onPanelMouseOut(MouseOutEvent event) {
Window.enableScrolling(true);
}
This is a bad solution because the main scroll bar disappear and the page is moving from left to right and back. I want to lock the scroll bar not hide it. Hiding will move the screen.
Is there a better way to lock the main scroll bar in GWT?
For this purpose only gwt introduced concept of layout panels. Use RootLayout Panel and other layout panels. Then your applications won't have body scrolls if you maintain the hierarchy. Layout panels also resizes child widgets on browser resize. So you will get an added advantage
EDIT
If you want a fixed header and scroll on the rest of the part, use RootLayoutPanel and add DockLayoutPanel to it. Set your header panel to dockPanel North side and add scroll panel to the center of the dockPanel
FlowPanel headerPanel = new FlowPanel();
headerPanel.setWidth("100%");
ScrollPanel bodyPanel = new ScrollPanel();
DockLayoutPanel myApp = new DockLayoutPanel(Unit.PX);
myApp.addNorth(headerPanel, 100);
myApp.add(bodyPanel);
RootLayoutPanel.get().add();
To hide and lock the scrollbar of the body
body {
overflow:hidden;
}

Display element outside the frame

I have to realize this design with Java Swing (see screen shot).
Is it possible? How can an element appear off the frame?
Add a JToolBar (non-floatable) to JFrame or parent JPanel (in the BorderLayout.NORTH position).
Put an Icon inside a JButton and add to tool bar.
Set "MODE DIAL" (or whatever) as the tool tip for the button.
Repeat for each icon/button required.
Use a PLAF to tweak the look.
You need to use a JWindow to contain your component.

How do I open a JInternalFrame centered in a JDesktopPane?

I am adding a bunch of JInternalFrames into a JDesktopPane, as the user selects to open various features through the menus. But I would like the internal frames to open centered in the desktop pane, as opposed to the upper left, where they seem to default.
How can I specify that the JInternalFrames open centered, or move them to the center after opening?
jDesktopPane.add(jInternalFrame); // jInternalFrame is not centered!
For reference, here is the solution I used, based on dogbane's advice:
Dimension desktopSize = desktopPane.getSize();
Dimension jInternalFrameSize = jInternalFrame.getSize();
jInternalFrame.setLocation((desktopSize.width - jInternalFrameSize.width)/2,
(desktopSize.height- jInternalFrameSize.height)/2);
Work out the top-left corner of the new location (based on the size of the JDesktopPane and JInternalFrame) and then call JInternalFrame.setLocation.
If you are using Netbeans (which is recommended for desktop apps) you just need to:
Select the form, right click and then properties;
Go to code tab;
Change "Form size policy" from "Generate Pack()" to "Generate Resize
Code";
Form Position (option above Form size policy) will be available.
Now you can set the for position as you wish :)
I would suggest the Window.setLocationRelativeTo(Component) method, which will center the window relative to a specified component. Instead of passing in a JDesktopPane, you might want to obtain the parent frame for a component, since otherwise, your JInternalFrame will be centered according to whichever component you pass in.
Here is a code sample:
private void showDialog(Dialog dialogToCenter, Component button) {
Frame frame = JOptionPane.getFrameForComponent(button);
dialogToCenter.setLocationRelativeTo(frame);
dialogToCenter.setVisible(true);
}
Add this void
public void addCentered(Component jif) {
desktopPane.add(jif);
jif.setLocation((desktopPane.getWidth()-jif.getWidth())/2, (desktopPane.getHeight()-jif.getHeight())/2);
jif.setVisible(true);
}
and when adding the jInternalFrame call:
addCentered(jifName);

Categories

Resources