I have a Java application that works perfectly fine on Windows and apparently on Mac as well, but I cannot get it to work on Kubuntu without overlapping, garbled output. I have tried launching the Java application with both the bundled OpenJDK as well as Oracle's Java 8.
Here's a picture:
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.net.URL;
import javax.swing.*;
import javax.swing.Timer;
import java.io.*;
public class spob { public static void main(String[] args) { new spob(); } private JLabel label; private String[] anArray = { "<html><font color=green>- spO2:91 pr:65</font></html>", "<html><font color=red>+ spO2:85 pr:77</font></html>", "<html><font color=green>- spO2:90 pr:68</font></html>", "<html><font color=orange>+ spO2:89 pr:76</font></html>", "<html><font color=orange>- spO2:89 pr:72</font></html>", "<html><font color=orange>+ spO2:88 pr:73</font></html>", "<html><font color=red>- spO2:87 pr:78</font></html>", "<html><font color=red>+ spO2:86 pr:73</font></html>", "<html><font color=green>- spO2:92 pr:74</font></html>", "<html><font color=green>+ spO2:90 pr:71</font></html>" }; private Random randomno = new Random(); public spob() { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("spO2 pr"); frame.setUndecorated(true); frame.setAlwaysOnTop(true); // Transparent window... frame.setBackground(new Color(255, 255, 255, 0)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BackgroundPane pane = new BackgroundPane(); // Set this to 0.0f to make it fully transparent pane.setAlpha(0.0f); //pane.setLayout(new BorderLayout()); //pane.setBorder(new EmptyBorder(10, 10, 10, 10)); frame.setContentPane(pane); label = new JLabel("-"); label.setFont(new Font("Tahoma", Font.BOLD, 28)); label.setForeground(Color.GREEN); frame.add(label); frame.pack(); Dimension size = frame.getSize(); size.width = 400; frame.setSize(size); frame.setLocationRelativeTo(null); frame.setVisible(true); Timer timer = new Timer(500, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { label.setText(anArray[randomno.nextInt(9 - 1) + 1]); label.getParent().repaint(); } }); timer.start(); } }); } public class BackgroundPane extends JPanel { private float alpha; public BackgroundPane() { setOpaque(false); } public void setAlpha(float alpha) { this.alpha = alpha; repaint(); } public float getAlpha() { return alpha; } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(getBackground()); g2d.setComposite(AlphaComposite.SrcOver.derive(getAlpha())); g2d.fillRect(0, 0, getWidth(), getHeight()); g2d.dispose(); } }
}I found documentation on Oracle's site to test transparency supported on a given system, and I ran the tests on my Windows machine. All three tests return true, but on Kubuntu only the PerPixel ones return true, the uniform translucency returns false.
Here's a picture:
Here's the code used:
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import static java.awt.GraphicsDevice.WindowTranslucency.*;
public class test { public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); boolean isUniform = gd.isWindowTranslucencySupported(TRANSLUCENT); boolean isPerPixel = gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT); boolean isShaped = gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT); GraphicsConfiguration[] configurations = gd.getConfigurations(); System.out.println("Default screen device: " + gd.getIDstring()); for (int i = 0; i < configurations.length; i++) { System.out.println(" Configuration " + (i + 1)); System.out.println(" " + configurations[i].getColorModel()); } System.out.println("isWindowTranslucencySupported Uniform: " + isUniform); System.out.println("isWindowTranslucencySupported PerPixel: " + isPerPixel); System.out.println("isWindowTranslucencySupported Shaped: " + isShaped); }
} 3 Reset to default