swing output is to small in netbeans - java

look at the image and you will understand what my problem
that's happened in this computer which is 4k UHD
this problem was under netbeans itself but i fix it using netbeans-ide-scaling-on-windows-8-10
when i tried to test it under swing this problem appear again.
setSize and setFont(new Font(MAX_FONT_SIZE)) are not what i'm looking for.
my working environment is:
windows 10 home
netbeans v8.0.2

May be you are not preparing the dimension on jframe.
Go to the design panel and click jframe.
set the preferredSize, width, height to change the size of jframe on properties window.
I think that it will be work.

Related

GUI on runtime differs from Designed GUI on NetBeans GUI builder

I am using JTabbedpane with a JPanel tabbed and all the components inside the panel are shown in the picture below:
This was, what I expected:
As given in below pic, the tabbed pane/panel is cropped, hence the buttons are not visible as designed in NetBeans.
This is, what I am getting:
Even when the GUI windows is maximized, it is still cropped as shown in below pic
Still looks same after maximizing the windows.
There's no additional code, I've written in GUI source code. And yet I am facing the issue.

Swing GUI not scaling from computer to computer

I designed (Netbeans Project) the swing GUI in one computer 15" screen.
Next, I moved the project to another computer 14" screen. When I launch the app in the 14" screen, it's like zooming the GUI and I can't see some part of it.
How can I let my design adjust itself from one computer to another?
Ps : In the GUI editor of netbeans, the size is the same in both computers
Update
I don't know if layout manage will solve it as they said in comments. I've just notice my Windows 10 displays 125 % zoom scaling on 1920 x 1080 resolution. When I switched to 100%, though all other applications of the computer looked aweful, the design I made in Netbeans looked exactly the same. What can I do then ? I think it's more related to Windows scaling than Swing's LayoutManager features. Am I correct ?
You need to use layout managers. Layout managers will organize your components in different ways depending on screen size, aspect ratio, etc.
Depending on what kind of GUI you want, you are going to choose a different layout manager. Once you have picked a layout manager, you can pass it to a JPanel on construction
JPanel panel = new JPanel(new FlowLayout());
More on info on how to use layout managers, here

Swing rendering appears broken in JDK 1.8, correct in JDK 1.7

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,....

Java desktop application with MIG layout on different screen resolutions

I am working on a desktop application in Java which uses Swing with MIG layout for building the GUI. I have a lot of drag&drop actions which require "fixed" screen positions (the application works with plugs and sockets). Currently we support only one screen resolution
Is it possible to build the GUI so that it is scaled somehow according to the screen resolution?
Thank you in advance
You can get the screen resolution this way:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Set the size of your JFrame accordingly to it. (Remember to use setSize() only on Frame not on child Components with their own LayoutManager)

netBeans gui problem

I have designed this gui in netBeans which has a canvas , a couple of JtextAreas and a Jbutton. It looks great in preview, the problem is when I run the actual program the text areas are shurnk until the program prints something in them, then they expand to their full size, the Jbutton is invisible until I mouse over it then it stays visible, there is also a Jlabel which just doesnt show up in the program at all only in preview. I have designed one more program in netbeans before but did not have these problems. Any idea what I could be doing wrong?
No idea whats wrong, but you should NOT be using a Canvas. That is an AWT component and you should not be using AWT components in a Swing application.
Actually the Canvas could be the problem. AWT components are painted on top of Swing components which could be causing the problem. That might be why the mouse over forces the button to show through the Canvas. I've never mixed AWT/SWING components so I don't know what wierd painting artifacts you will encounter.

Categories