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.
Related
I need to recreate the translucent border of JFrame or JDialog that appears when setting the windows look and feel in swing.
I need it because Windows LaF does not let you access the title bar (on the border). In fact, I need to apply a MouseAdapter to the JDialog that gets notified when it is dragged/pressed/released. In windows laf, as you cannot get access to the bar component, you can only apply a ComponentListener which gives you notification only when moving (so you don't capture anything when the user has grabbed it but hasn't moved yet, or either when the user "releases" it).
Therefore, I decided to go with undecorated dialogs and apply the listeners to my custom bar. However I want the custom dialog looks exactly as in windows laf (it means I need to recreate the border).
I'm not very experienced in Graphics2D to override the paintBorder() method, so I'm asking for your help.
Has anyone ever faced this problem and has a tested solution?
As of the Java Platform, Standard Edition 6 (Java SE 6) Update 10 release, you can add translucent and shaped windows to your Swing applications.
This means that you can have your JFrame emulate a native window with the rounded corners and transparency.
In your case, your approach would be in the JFrame level instead of the border level because the border is painted on top of the JFrame (or JDialog, for that matter). Therefore, if the JFrame is not already rounded, for instance, the paintBorder() method will still be painting on top of a rectangular area of the screen.
Check this tutorial from Oracle covering shaped and translucent JFrame.
I have a JPanel v. Function below creates a full-screen Jframe, called window, which will feature this JPanel. I have:
protected final void fullScreenMulti(final JPanel v) {
final JFrame window= new JFrame();
window.setUndecorated(true);
window.add(v);
//window.setVisible(true);
.
.
.
window.validate();
window.repaint();
GraphicsDevice gdev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
gdev.setFullScreenWindow(window);
DisplayMode mode = gdev.getDisplayMode();
window.setSize(mode.getWidth(), mode.getHeight());
}
This works for the default render that is written for the code. However, selecting the GL renderer which uses JOGL, makes the fullscreen frame blank and I get a white screen. You will have to switch-tab in and out, or press Start for the Panel to be painted. I tried changing the background of window using:
Container c = window.getContentPane();
c.setBackground(Color.yellow);
that doesn't do anything though and I still get a white screen. (Although when i debug, I can see that the background property is successfully applied.)
Also clicking on the blank area of a second screen(The window is hosted on the first screen), or even clicking the Start button, SOMETIMES makes the frame go Black and my mouse adaptor fails to work afterwards. (what exactly could be happenning here, how can I investigate it?) Other times, it has the same effect of Alt-tab.
Haven't done much Swing stuff in Java and a I'm bit lost. Seeing that it seems to be working fine on one renderer and not on the other, suggests that it has something to do with the GL renderer, but the renderer works fine when rendering JPanels in my non-full screen mode; Also my understanding is that the role of the renderers is merely to buffer the video that is featured on my JPanel.(I mean that's what renderers do, right?) so it is probably a case of some setting not being specified above, but the original renderer takes care of it. Any suggestions what that might be?
edit: needless to say, taking out window.add(v) will make the frame render fine and the result of changing frame background etc. that was previously not working, will now be visible on the frame.
This is a known problem. -Dsun.java2d.noddraw=true solves it.
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);
I have a transparent undecorated JFrame that I set using AWTUtilities.setWindowOpaque(this, false). On the JFrame, I have a scrollpane; it works perfectly on Windows. On the Mac, the whole JFrame is draggable; so when I try to scroll through the scrollpane by clicking and holding the mouse on the scrollbar, the entire frame moves instead of the scrollbar thumb. I also tried to use setBackground(new Color(0,0,0,0)) instead of setWindowOpaque(), but it has the same problem. Any ideas on how to fix this?
As suggested in this similar thread, try:
getRootPane().putClientProperty("apple.awt.draggableWindowBackground", Boolean.FALSE);
If you choose to use this, the scrollbar will be usable and the window won't drag. However, you may be stuck with an immovable window, unless you add a MouseMotionListener and move the window around in the mouseDragged() method using a call like frame.setLocation().
Instead, you might be able to force the user to click on the scrollbar's arrow buttons, rather than drag the scrollbar itself... But that's not the most user-friendly idea I've ever seen.
I'm working on a Swing app for Solaris, and I have a problem that shows up only when the system LANG variable is set to a double-byte language such as Korean. The problem is that components are being resized and this is messing up the layout of the app:
1) LANG set to Korean
2) LANG set to English
Changing the Locale in the Java code itself does not affect the display (if LANG=English and Locale is set to Korean, everything is fine. If LANG=Korean and Locale is set to English, the issue happens).
Is this caused by the LayoutManager (I'm using BorderLayout)? Is there any way to prevent this from happening? So far the only workaround I can use is changing the system locale to english right before launching the app.
Here is some example code on what I'm doing:
Box container = Box.createVerticalBox();
container.add(label1);
container.add(label2);
container.add(label3);
container.add(label4);
container.add(label5);
Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
TitledBorder titledBorder = BorderFactory.createTitledBorder(border1, LocalizationTools.getString("STR_1"));
Dimension lDim = new Dimension(550, 100);
mypanel = new JPanel(new BorderLayout());
mypanel.setPreferredSize(lDim);
mypanel.setMaximumSize(lDim);
mypanel.setMinimumSize(lDim);
mypanel.setBorder(titledBorder);
mypanel.add(container);
Here are some strings used in the example:
1) "\ud648 \ub514\ub809\ud1a0\ub9ac"
2) "\ubcc0\uacbd \uc2dc\uac04"
3) "\ub9c8\uc9c0\ub9c9 \uc791\uc5c5"
Here are a few things to try:
Ensure that you are calling pack() on the parent Window and not interfering with any component's preferred size.
Use a compound border, adding an EmptyBorder to your TitledBorder.
While debugging, add padding to the BorderLayout and use color for highlight.
Edit your question to include an sscce that exhibits the problem; a native user may see the problem (text cut-off at bottom) more clearly.