java System.setProperty not affecting anti-aliasing; command line option works - java

I'm trying to make a java Swing program default to anti-aliasing when run on Linux. It works when I pass the settings as command line options or using _JAVA_OPTIONS, but not using System.setProperty().
I'm using Java SE 6 on Centos 5.5 via VNC with gnome metacity WM.
public class Test {
public static void main(String args[]) {
System.setProperty("useSystemAAFontSettings", "lcd");
System.setProperty("swing.aatext", "true");
JFrame frame = new JFrame("Test");
JButton button = new JButton("Button");
frame.getContentPane().add(button);
frame.setSize(100,100);
frame.setVisible(true);
}
}
Any clues what I'm doing wrong? Thanks.
PS: The swing.aatext setting seems to have no effect in any case, but I included it as I saw it as part of the solution elsewhere.

Related

Java crashes when creating a JFrame

I am baffled at this issue. I just wanted to create a JFrame for testing, this is the only class:
import javax.swing.*;
public class TextPaneTest extends JFrame {
public TextPaneTest(){
setTitle("Test");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(200, 200);
setVisible(true);
}
public static void main(String[] args){
new TextPaneTest();
}
}
I am using IntelliJ IDEA 2019.2.4 as my IDE.
The result is a small white JFrame opens up for 2 seconds and closes. You can't move or resize the window and the cursor remains in "wait" mode when you hover the frame.
This is my project structure:
And this is my run configuration:
There is no error message or exception. All the console shows is:
Process finished with exit code -1073740771 (0xC000041D)
I've already done a clean reinstall of both the JRE and JDK
This is my current java -version:
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
My OS is Windows 10 Home Single Language 1903
I don't know what else to add. I've been using Java for the past 5 years as a hobbyist and I've never came across an issue so fundamental as this.
Update
Tried instantiating TextPaneTest() using SwingUtilities.invokeLater()
Tried building the JAR and running from a command window
None has worked so far. Exactly the same behaviour.
Update 2
Fixed it by switching the 64 bit JRE for the 32 one. Is this a bug with the 64 one or could there be an underlying problem?
I cannot reproduce the issue on my macintosh, but I notice you are doing everything on the main thread. You shouldn't do that. Make sure all events happen on the Event Dispatch Thread. For example,
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TextPaneTest();
}
});
}

JFrame scaling in Java 9

Exactly the same code running under Java 9u4 on the left and 8u144 on the right on Windows 7.
Java 9 seems to making the window larger. What is causing this - JEP 263? How can I disable it?
public class SimpleFrame {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new JLabel("Horse"));
frame.setSize(new Dimension(200, 100));
frame.setVisible(true);
}
}
I found this obscure option in a substance bug report. This fixes the issue for Swing applications.
-Dsun.java2d.uiScale=1.0
If you're using JavaFX you'll need
-Dprism.allowhidpi=false
Unfortunately I cannot find official documentation for either of these options

Java error: "Can't open input server /Library/InputManagers/Inquisitor"

I'm just now getting into GUI's in Java and when experimenting with JFrame I get the following error:
java[3126:71534] Can't open input server /Library/InputManagers/Inquisitor
Despite the error the program runs fine, but I'd like to know what this is about as I couldn't find much about Inquisitor anywhere.
Running Netbeans 8.0.2 and Java 8 Update 40 on OS X Yosemite (10.10.2). The java code being run is:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Ikkuna extends JFrame implements ActionListener{
JTextField syöte;
JLabel vastaus;
JButton painike;
public void setTitle(String string){
super.setTitle(string);
}
public Ikkuna(){
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setTitle("Celsius / Fahrenheit -muunnos");
this.setSize(400, 200);
this.setResizable(false);
JPanel paneeli = (JPanel) getContentPane();
syöte = new JTextField(10);
vastaus = new JLabel("tuntematon");
painike = new JButton("Laske");
painike.addActionListener(this);
syöte.addActionListener(this);
paneeli.setLayout(new FlowLayout(FlowLayout.LEFT, 10,10));
paneeli.add(syöte);
paneeli.add(vastaus);
paneeli.add(painike);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
vastaus.setText("" + ((Integer.parseInt(syöte.getText())*1.8+32)));
}
public static void main(String[] args){
Ikkuna i = new Ikkuna();
}
}
TLDR: Don't worry about it, it has nothing to do with your code, although you're probably better of removing Inquisitor extension as there's a good chance that it's not working properly.
InputManagers are intended to be Keyboard/Mouse extensions for applications. The idea is that the code is loaded into applications and can change their behavior in relation to Mouse/Keyboard input, but are generally used as a mechanism for extending applications. They became more restricted in 10.5, where they had to be in the system supported location only (/Library/InputManagers), and stopped being loaded entirely on 64bit mode.
Java 8 is a 64bit only application, so if you're seeing this error, then it's probably because the extension is not being loaded because it's a 64bit application and the system doesn't load extensions in this case.
The extension Inquisitor doesn't look to have been updated in a long time, and was used to extend the functionality of Safari, adding auto-complete to the search bar. The default search functionality of Safari now includes auto-complete, so I would consider it obsoleted.
If you want extended functionality for Safari, there are other plugins which extend the behaviour, such as Glims (I used to use it, but stopped because I felt it destabilized safari more than usual).
Opening the /Library/InputManagers folder (open a Finder window, hit Command-G to get a location field and type in the directory, then hit enter) will allow you to see what input managers are present on the system.

Why is my Java swing window not showing up?

so I'm starting to learn Java Swing, following a YouTube video.. installed Java 8 and NetBeans 8.0 in Linux Ubuntu 14.04. Made a new Java application, and wrote the following code:
package basicswing;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
public class BasicSwing extends JFrame {
JPanel p = new JPanel();
JButton b = new JButton("Hello");
public static void main(String[] args) {
new BasicSwing();
}
public BasicSwing() {
super("Basic Swing App");
setSize(400,300);
setResizable(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
p.add(b);
add(p);
setVisible(true);
}
}
When I clean, build, and then run the project, it shows that a Java project is running, but I don't see the Frame, it doesn't pop up.. I don't actually think it's a code issue, I've tried it with different code, and the frame still doesn't show. I can't figure out if it's a NetBeans issue or a Java issue.. or maybe something else?
It is an environment (NetBeans maybe?) issue. Try running from command line:
$ javac BasicSwing.java
$ java BasicSwing
The code is correct and displays the frame.

Programmatically setting the dock:name Java Mac OS X JVM property

Is there a programatic alternative to setting the dock:name Java Mac OS X property by doing
java -Xdock:name="My App Name" -jar myapp.jar
, or is this the only way to set the dock:name property?
It's been a while, but I believe you need to do the following (this is assuming you're using Swing):
Put your main() method in a separate class from the JFrame.
Before creating the JFrame, set the "com.apple.mrj.application.apple.menu.about.name" system property.
For example:
public class Launcher {
public static void main(String[] args) {
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Hello World!");
JFrame jframe = new MyJFrame();
jframe.setVisible(true);
}
}
The Apple extensions are documented here:
http://developer.apple.com/mac/library/documentation/Java/Reference/1.5.0/appledoc/api/overview-summary.html
I looked at com.apple.eawt.Application, which gives you access to the icon and menus... but not title, unfortunately.
I am guessing the prescribed approach is to roll out your own App Bundle, as detailed here: http://developer.apple.com/Mac/library/documentation/Java/Conceptual/Java14Development/03-JavaDeployment/JavaDeployment.html

Categories

Resources