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,....
Related
In a JFace wizard I have a main composite and a ComboViewer within that composite. First time when I open the window I can see the ComboViewer in a proper size within its parent composite, then when I resize the JFace wizard (through clicking the maximize option on the window) ComboViewer does adjust itself to the size of the window and then I close the window without minimizing it back. Everything is fine until this point.
But when I reopen the wizard I see that the ComboViewer resizes itself to a very very very small widget which could hardly be seen, this strange behaviour happens only through this workflow -
1) Open the wizard.
2) Maximize the window and close the wizard.
3) Reopen the wizard and you see that the ComboViewer resizes itself and
displays as an extremely small widget.
4) Again you maximize/minimize the main window then the ComboViewer draws itself
to the original intended size.
[PLEASE NOTE - This strange behaviour happens only with SWT 3.7, I tried resetting my target platform in Eclipse with SWT 3.5 and the ComboViewer behaved absolutely perfect under all the circumstances, only with SWT 3.7 I was able to reproduce this issue consistently]
Here's my code for the ComboViewer, it's just a normal code -
final Composite c = new Composite(parent, SWT.NONE);
//layout for the composite
GridLayoutFactory.fillDefaults().extendedMargins(0, 0, 0,5).numColumns(3).applyTo(c);
ComboViewer selectViewer = new ComboViewer(c);
selectViewer.setContentProvider(new ArrayContentProvider());
selectViewer.setLabelProvider(new CustomLabelProvider())
selectViewer.setComparator(new CustomComparator());
selectViewer.getCombo().setVisibleItemCount(15);
I tried searching through Eclipse community forums to check if there was a known Bug logged for this issue only with SWT 3.7, or to check if anyone else has figured out this issue and if it's a typical issue with SWT 3.7 but could not find any relevant info on the Internet.
Can someone please tell me if this issue is already known and there's nothing that can be done about it in the production code unless the next release of SWT or something? or if there's a workaround for this issue that has already been figured out?
I found a solution to this issue long ago but missed out on updating this post.
We need to explicitly call the layout method to force a lay out of all widgets that are in the parent hierarchy of the changed control (in my case the control is the comboviewer) up to and including the receiver.
this.layout(new Control[] { comboViewer.getCombo() });
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.
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).