I'm currently working on a stand-alone java application running on Windows 7 with Aero.
I'm trying to use the system look and feel but I got some trouble with the look of the JInternalFrame.
http://img11.hostingpics.net/pics/300466buginternalframe.png
This is a screenshot of the internalFrame demo from Oracle
As you can see, I use the system look-and-feel, but the lower border is cropped and the title buttons are too close of the right side of the window. Those also seems to be a bit cropped.
I search for a fix to those issues but the only advice I found is to reduce the buttons width by changing the UIManager properties:
UIManager.put("InternalFrame.titleButtonWidth", 10);
This line do reduce the buttons but they still seems to be cropped. And it does not fix the lower border issue.
How could I possibly fix these 2 issues using the system look-and-feel?
The only way I found to bypass this bug is to change the internalFrame close icon for a custom icon in the UIManger which is a bit smaller than the original close icon:
ImageIcon closeIcon = new ImageIcon(ImageIO.read(new File(iconPath)))
UIManager.put("InternalFrame.closeIcon", closeIcon);
Related
I try to change icon in my javaFX application. It starts but icon doesn't change in both application top left corner and in task bar. I use this code to change the icon:
Image icon = new Image(new File("window_icon.png").toURI().toString());
stage.getIcons().add(icon);
But it seems to have no effect at all (no exceptions as well). BTW: I'm sure the file exisits. I also tried different images and formats(.png, .ico and .jpg)
(I use ItelliJ 2021.3.2 on windows 10 and create scene with FXMLLoader)
What can be the problem?
Update: tried 16x16, 32x32, 64x64, image's original 256x256
using Image("file:window_icon.png") doesn't change anything
The solution that worked for me is using ResourceStream. Putting the source image into /src/main/resources/{packagename} folder made this line of code work:
stage.getIcons().add(new Image(getClass().getResourceAsStream("window_icon.png")))
Thanks to #JoopEggen for the hint
first time making a question here. First of all, Eclipse (as far as I'm aware of) don't let you re dimension images through the design tab directly so to solve this I made a method that convert the icon from ImageIcon to image, re dimension it and then convert it back. The problem is that when I use the re dimensioned image it looks like this in a JButton.
I have already tried to create a emptyBorder in the JButton but that only remove the border of the button, not the icon. How can I remove it?
Edit:
Just noticed that when the Window is not focused the border is not there? Image related
Just noticed that when the Window is not focused the border is not there?
button.setFocusPainted( false );
I have been having this problem for quite some time and I've been unable to find the solution anywhere on the internet.
I have a JDialog as my main frame and I need to be able to change the transparency of the window. Normally this would not be a problem if I was to call setUndecorated(true) on it, but I do not want to do that. I want the title bar to appear at the top under the system look and feel.
The interesting part is that on my Mac, changing the transparency works just fine with the system look and feel, even though the JDialog is still "decorated".
Here's an image of my JDialog so you know what I'm dealing with:
I need to use the system look and feel, but I also need to be able to change the transparency of the window.
When I try, I get the following exception on windows:
"Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The dialog is decorated"
If I set it to undecorated, I lose the title bar at the top which is not an option. Anybody know a way around this?
I am placing [OK] and [Cancel] buttons horizontally in a Box (which has BoxLayout). Later I add this Box to BorderLayout.PAGE_END in content pane of JDialog. This works perfect in Windows, so [OK] is to left of [Cancel] - just like I have added.
When I test in Linux, the placement of buttons is same as Windows - [OK] to left of [Cancel]. This, again, follows from code.
However, in Linux (Ubuntu), the default placement for buttons is [Cancel] to left of [OK]. This contrasts with my code and placement of buttons.
So, my question is : Whether Java has some kind of constant - say OS_PLACEMENT, which can be set somewhere which will make [Cancel] button appear to left of [OK] in Linux? I am asking this because I know Java supports constants for RTL and LTR layout. Thus, I thought, there might be some constant(s) related to this kind of placement.
I wish to mention that I do set L&F of my Swing app to System L&F. Following is my first line in main()
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
When you say Linux (Ubuntu) you mean Gnome, right? The button placement by default (OS) of Gnome (Gtk) is placing Cancel button to the left.
You can try to change the Look and Feel of Swing :
How to Set the Look and Feel
No, Java will not do this automatically for you.
Consider using the free "JGoodies Form" library. It has a class called "ButtonBarBuilder" which will lay out buttons in the correct order according to the user's OS.
Otherwise you must manually inspect the value of System.getProperty("os.name") and lay out the buttons according to the value.
Some LayoutManagers automatically do this for you, for example DesignGridLayout and MigLayout detect the OS the application is running on, and based on it, will choose the right position for OK and Cancel (and also other specific buttons).
For example, with DesignGridLayout you would do:
DesignGridLayout layout = new DesignGridLayout(myDialog);
layout.row().bar().add(okButton, Tag.OK).add(cancelButton, Tag.CANCEL);
I am trying to undecorate a JInternalFrame, i.e. remove the default titlebar using the following code;
BasicInternalFrameUI ui = (BasicInternalFrameUI)internalFrame.getUI();
ui.getNorthPane().setPrefrredSize(new Dimension(0,0));
I works on windows but the second line throws a NullPointerException on MacOS
Any ideas why and how to get round it?
On Mac, the JInternalFrame doesn't have a north pane. Only execute the code on none Mac OS platforms;
// only remove the northpanel for none Mac OS
if(!(System.getProperty("os.name").startsWith("Mac OS"))){
BasicInternalFrameUI ui = (BasicInternalFrameUI) getUI();
ui.getNorthPane().setPrefrredSize(new Dimension(0,0));
}
So much about cross platform :-(
I don't use a Mac so I don't know what is causing the problem.
A JInternalFrame without the title bar loses its ability to be dragged. You should be able to accomplish the same goal by just adding a JPanel to the desktop. You would need to set the bounds of the panel. You might also want to use one of the internal frame custom borders on the panel:
UIManager.getBorder("InternalFrame.paletteBorder");
UIManager.getBorder("InternalFrame.optionDialogBorder");
Or maybe another option is to use:
internalFrame.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
This will replace the title bar with a small palette that can be used to drag the internal frame without the buttons or title.