When vertically maximizing a window on my win7 64 bit machine by dragging the top or bottom edge of the window to the top or bottom portion of the screen respectively, the application becomes unresponsive and displays a black section or some other visual distortion. Does not happen when vertically maximizing by double clicking on the edge, or regular maximizing.
Since its happening with the Java Tutorial programs (I selected a few at random, and they all do it), is this some kind of bug in Swing - or is there something I can do?
This SSCCE shows the problem under Windows 7 (both 64-bit and 32-bit versions), compiled with JDK 1.7.0_07, running JRE 1.7.0_07:
public class Expander extends javax.swing.JFrame
{
public Expander()
{
this.setBounds(0, 0, 300, 300);
}
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new Expander().setVisible(true);
}
});
}
}
Problem appears to be that no resize event is passed to the content pane of the JFrame. The JFrame's paint method does get the new size, but nothing inside it does. Problem does not appear under version 1.6 (can't test it under Linux as, apparently, the auto-resize behavior is unique to Windows).
See http://www.coderanch.com/t/601457/GUI/java/Vertically-Maximizing-Window-Swing for a more detailed discussion. I have filed a bug report on this at bugs.sun.com.
I am using a system of the i7-2600k, ati radeon 6800 and win7 64bit and i've never had any such problems. Are you using the latest version of Java? I made the following program. It works fine on my system under without any problems.
Download link to JPositioner : JPositioner
Please check and let me know if u are facing the same problems even with JPositioner.
Related
I have installed IntelliJ IDEA (13.1.1 #IC-135.480) and JDK 1.8.0 (x64) and I generated some GUI with the GUI Form designer.
Then I ran the code and realized that something is not alright.
Here is a Screenshot of my GUI:
The rendering of the Font seems to be not OK. Additionally the Button looses its Text, when I move my mouse over it.
So I installed JDK 1.7.0_40 (x64), recompiled the Project and ran it again.
The following Form appears, when i use JDK 1.7:
The Rendering seems to be OK and the Button is also OK.
So I installed the newest Graphics and Chipset drivers and much more, but the problem still exists.
Have you ever had such problems with Java Swing UIs? Could you help me to fix my problems?
Any help would be greatly appreciated.
UPDATE:
I created a small Project with only 1 JTextArea and 1 JButton and i have the same rendering problems.
According to Andrew Thompson i changed the setSize() and I start from EDT. The Example below:
package at.maeh.java.client.simpleTextClient;
import javax.swing.*;
import java.awt.*;
public class SimpleClient extends JFrame {
private JPanel panel1;
private JTextArea textArea1 = new JTextArea();
private JButton button1 = new JButton();
public SimpleClient() {
super("SimpleClient");
// Panel
panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
// BUtton
button1.setText("TestButton");
// TextArea
textArea1.setColumns(40);
textArea1.setRows(15);
// Add Components
panel1.add(textArea1);
panel1.add(button1);
// Add to Frame
this.getContentPane().add(panel1);
// pack and set Visible
pack();
setVisible(true);
System.out.println("Constructor EDT: " + SwingUtilities.isEventDispatchThread());
}
public static void main(String[] args) {
SwingUtilities.invokeLater(SimpleClient::new);
System.out.println("Main EDT: " + SwingUtilities.isEventDispatchThread());
}
}
The result is a simple JFrame with the Components in it.
When I write some Text, or moove my mousePointer over the Button the components get rendered like this (Text: testsentence.123; Button-Label: TestButton)
For those whose problem has not been solved; try this solution:
Set the global environment variable "J2D_D3D" to "false" inside the OS.
According to Sun, this setting is used to turn off the Java 2D system's use of Direct3D in Java 1.4.1_02 and later.
ie: simply create a environmental variable with name "J2D_D3D" and value "false" without the quotes.
this has solved my rendering problems, hope it does yours also.
Finally I found the solution for my problem. I had to change the energy control settings of my NVIDIA GeForce 620M to maximum performance.
You can follow this steps :
Right-click on desktop and click NVIDIA Control Panel
Select 'Manage 3D Settings' in the left pane
Select the "Program Settings" tab in the main window
Click 'Add'
Navigate to your java folder (C:\Program Files\Java\jre1.8.0_20\bin) and select javaw.exe and press 'open'(this step will probably depend on your operating system but should be pretty easy to find)
Where it says 'Select the preferred graphics processor for this program' click the drop-down and choose 'High Performance NVIDIA processor'
Click 'Apply' in the bottom right and you're good to go.
I have exactly the same problem. What I found after duffys quality setting adjustion:
My Notebook runs both an Intel HD 4000 and a NVS 5200M. Running Swing applications with Java 7 is fine on both cards. With Java 8 Swing GUIs rendered by the Intel card (regardless of quality settings) look crumbled (as in duffys Screenshot), using the NVS 5200M they look as they used to.
Could not find anything on the java bug tracker, on the otherhand it is hard to describe this bug.
textArea1.setSize(500, 300);
There is a problem. Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement or sizing of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them1, along with layout padding & borders for white space2.
Dell Vostro 5480 with ubuntu mate 16.04 I had a similar issue.
It's fixed changing the Nvidia Driver, using an additional driver.
And select the NVidia Profile.
Similar fix to duffy356:
Lenovo T430s running Windows 7 64 bit with NVIDIA NVS 5200M alongside HD 4000.
Update to Java 8 update 5 created graphics and button corruption for two Swing apps, jEdit and Freemind.
Using the NVIDIA control panel applet to change the global settings for Power Management Mode to "Prefer maximum performance" looks like it fixed this issue.
Not sure if there is a lurking issue with how the apps set sizes.
steps:
control panel
system and security
system
Remote settings
Advanced tab
click Environment variables
create a J2D_D3D variable
and set the value to false.
worked for me,....
So I'm using Ubuntu and when I want to enter fullscreen mode in Java, a normal window appears with max screen size, instead of a fullscreen window without title bar etc. I admit, I'm not even sure what the fullscreen mode should look like in Java, because I have not tried it on any other OS. But I assume it should be a screen without title bar.
Anyone else who has this problem?
This is the code I use. ; pretty straight forward.
public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice vc = env.getDefaultScreenDevice();
JFrame window = new JFrame();
window.setUndecorated(false);
window.setResizable(false);
vc.setFullScreenWindow(window);
}
On Ubuntu (probably other Linux distros as well) it doesn't work. Full screen mode in Java doesn't cover the full screen. It leaves the toolbars out. Always, whatever you do.
I tried the two examples above and the examples from the official FSEM tutorial and some application I know are using Java/Swing and Full screen mode (FreeCol and TripleX) and noone was able to cover the task/toolbar areas of the screen.
My configuration is Ubuntu 12.10 with either OpenJDK or SUN-JRE 1.7.0_09 and either Unity or Gnome. Interestingly the java call to isFullScreenSupported() returns true. So, while the Java JRE says it supports full screen exclusive, it doesn't.
Some possible explanations might be given in another question.
On win7, with this code (I set the undecorated flag to true as suggested by #Gilberto and added a RED panel) it seems to work OK. If it does not work on Ubuntu, then it may mean that FullScreen mode is unsupported:
import java.awt.Color;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main {
public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice vc = env.getDefaultScreenDevice();
JFrame window = new JFrame();
JPanel comp = new JPanel();
comp.setBackground(Color.RED);
window.add(comp);
window.setUndecorated(true);
window.setResizable(false);
vc.setFullScreenWindow(window);
}
}
This thread is very old but still comes in ACTUAL search results but with wrong answers. So i'll post actual the real solution.
Swing full screen will be set with the setExtendedState() function, not with the setFullScreenWindow() function!
JFrame myFrame = new JFrame();
....
myFrame.setExtendedState(MAXIMIZED_BOTH);
Then u'll have a decorated full screen window, with all buttons and a correct toolbar optic and it works fine with Ubuntu and any other OS.
Though this might in most cases not be applicable I'd like to share my solution to this problem.
In my case, I frequently need to develop Java/Scala apps for our university institution (psychological tests). To circumpass this issue we decided to install sawfish on our experimental pc's.
If this solution is applicable to your needs you can install (an extremely outdated) sawfish through Ubuntu facilities (Software Center, Aptitute, apt-get) or - what I'd prefer - install or compile an up-to-date sawfish manually.
Other window and/or desktop managers might give similar functionality, but we experienced artifacts when we tried XFCE or LXDE with disabled/deleted panels.
I'm developing a GUI for a moderately complex application using Java AWT for the GUI and it looks great when I run it in X11 (with any desktop manager) on linux but in Windows XP it looks weird.
Actually, at first it looks okay but if I need to change the background color of any of the frames, I can't change it back to the correct color afterwards. When I try to set the background color back to normal the frames get what looks like solid white backgrounds rather than the beige color that native applications have in XP. I can't seem to make them look more natural.
I've tried:
frame.setBackground(null);
and
frame.setBackground(java.awt.SystemColor.window);
with no success. Any suggestions would be appreciated.
Thanks in advance for any help!
-Jonathan Perry-Houts
Edit: Here's a quick example to demonstrate what I mean, I would expect this small empty frame to be beige but instead it's white in Windows XP:
import java.awt.*;
public class HelloWorld {
public static void main(String[] args) {
Frame f = new Frame("Hello World");
f.setPreferredSize(new Dimension(200, 200));
f.setBackground(SystemColor.window);
f.pack();
f.setVisible(true);
}
}
As stated in my comment... have you tried SystemColor.control? It should work! Be wary, however, when using SystemColor... it is a relic from a time when Motif and Windows 95-98 UI were predominantly used. More often than not, it will be utterly inadequate for dealing with modern UIs.
MAJOR EDIT
I have restructured my question to be more appropriate and less arbitrary, but the basic message still holds.
What I want to do is make some text appear without an associated window in any of the following languages: Java, C or python. It would just be the text that I want to appear completely overlaid on whatever you happen to currently have on your desktop. It would be overlaid on all programs, etc.
Any recommendations/starting points on how to do this?
OLD POST
I've heard rumors that it's possible to use assembly to make "images" appear (I don't know what they'd actually be considered, what I heard was that my friend professor made a semi-transparent, green dollar bill sign appear and bob up and down on the lower right side of the screen)
So my question is:
Are there any assembly commands/series of commands to make things appear on your screen?
Can anyone point me in the direction to use assembly to interact with what appears on the screen?
Is it possible to have an independent symbol appear without a window associated with it? Or alternatively, is it possible to make the background window completely transparent while still keeping the image intact?
How difficult would it be to create an assembly program which makes text appear in this manner? (i.e. overlaid whatever you currently have on your screen without opening it's own window)
NOTE if you would like to provide any examples, which would be greatly appreciated, I am currently on a mac so my computer only interprets AT&T syntax
OLD POST
Ultimately you DO create a window, you just set its background to transparent. Drop this code into a file called test.java and give it a shot - just tried it out on Mac OS 10.7 and it works. (The text shows up black near the top left corner of the monitor - you have to look carefully to see it.) Note that according to this post you do need Java > 1.6.
import javax.swing.*;
import java.awt.*;
public class test extends JWindow{
public test(){
super();
this.setSize(500, 400);
this.setLocation(50, 50);
setBackground(new Color(0,0,0,0)); // this is the critical line - that fourth 0 represents alpha (or opacity)
setAlwaysOnTop( true ); // keeps it in the foreground so you don't click away from it - note that clicks on the transparent part DO pass through to the desktop, at least on Lion
JLabel testLabel = new JLabel("Floating text hah");
this.add(testLabel);
}
public static void main(String[] args){
System.out.println("Sup");
test t = new test();
t.setVisible(true);
}
}
Hopefully this puts you on the right path.
This is certainly possible, but will depend on your operating system and windowing system as most operating system prevent a program from directly accessing the video memory (to allow program to share it, they have to impose some restriction). The basic idea is to create a transparent borderless window and to draw your content in it. If you ask the windowing system to display your window before all the other window (Z order), then, it will appear as if your program is directly drawing to the screen.
There are some library that does exactly that. For X11 you can use libXosd. For Windows, the OSD executable can display a single string (the source don't appear to be available).
To align my JFrame from righ-to-left, I use:
setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
but this works only if I use the following style (decoration) of the JFrame:
public class RightToLeft {
public static void main(String []args){
javax.swing.SwingUtilities.invokeLater(new Runnable(){
public void run() {
try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); }
catch (Exception e) { e.printStackTrace(); }
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("العنوان بالعربي");
frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
but I want it to work without this decoration. How to solve this issue?
EDIT:
#mre I want a JFrame like this one:
EDIT2:
I really really need this issue to be fixed, so I offer 500+ to who will give a JFrame like this (with WindowsLookAndFeel):
The following explains what you observe through your code snippet:
ComponentOrientation is applicable only to Swing (and AWT actually) components.
When using JFrame.setDefaultLookAndFeelDecorated(true);, then the whole frame decoration is performed by Swing (the LookAndFeel itself in fact), so this works as expected.
If you don't set this option though, that means that the OS is in charge of the frame decoration, however the OS cannot be aware of the ComponentOrientation used by your Swing components!
I expect the OS (did you mention what OS you use exactly? It seems to be Windows 7 right?) to perform the correct decoration based on the currently selected Locale. Hence if you have an Arabic locale setup and selected on your OS, I guess all windows decorations are right to left. Did you try changing that Locale (through the "Region and Language" control panel)? Did it work?
Note: I don't think that you can change these OS settings directly from Java, but you can read them with Locale.getDefault().
To sum up:
first of all, you have to ensure that your OS is properly configured in terms of text orientation; sorry I can't help much here because I don't have any right-to-left languages installed on my Windows machine.
then, use the system look and feel and ensure that JFrame.setDefaultLookAndFeelDecorated(false);
if that doesn't work, then you may consider posting your code snippet, along with your system configuration to Oracle Java bugs list
What follows are extra notes on how to improve this part of your code (but this is not a fix for your issue)
By the way, if you let the user define its OS language preferences, then you shouldn't explicitly hard-code frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); but rather use something like:
frame.applyComponentOrientation(
ComponentOrientation.getOrientation(Locale.getDefault()));
Where Locale.getDefault(), unless explicitly changed within your application, will return the OS-level currently selected Locale.
Also note that it is preferable to use applyComponentOrientation() rather than setComponentOrientation(), because the former recursively sets the given orientation to the whole hierarchy of components.
Finally, you will have to ensure in your windows that the LayoutManager used is right-to-left aware; this is normally OK with all standard Swing layouts, but not for all 3rd-party layout managers, if you use some.
#Eng.Fouad
just joke and this one ???...
code:
import java.awt.ComponentOrientation;
import javax.swing.JFrame;
import javax.swing.UIManager;
import org.pushingpixels.substance.api.skin.SubstanceOfficeSilver2007LookAndFeel;
public class RightToLeft {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
try {
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel(new SubstanceOfficeSilver2007LookAndFeel());
} catch (Exception e) {
e.printStackTrace();
}
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("العنوان بالعربي");
frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
});
}
private RightToLeft() {
}
}
I suspect it has to do more with the OS. Normally (if you don't call setDefaultLookAndFeelDecorated) it is the OS that provides the frame decoration, not the LAF.
You should try changing your preferences in the OS to say you want right to left orientation.
Sorry, I don't know where those settings would be.
Once you do this, then you should be able to remove the call to setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
as the LAF will pick up the OS settings from the Locale.
EDIT
This Link describes how to enable right-to-left text on Windows 7. Then I think you would also need to change your locale.
It looks like the Component Orientation feature is not supported with the Windows LookAndFeel (at least not for the title bar)
Here is one posibility. This utility is designed for Mac users who have switched to Windows and want the window buttons on the left, but it should serve the same needs as yours.
This solution has nothing to do with Java (so I don't know if it's even acceptable for your needs) and sounds like it would be external to your application. I have not been able to try it out myself (I'm not running Windows), so I can't vouch for it, but it might be worth a try.
You only need to add this line of code and I am sure it works 100%.
frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);