O JPanel transparente do aplicativo Java é truncado quando executado no Kubuntu

0

Eu tenho um aplicativo Java que funciona perfeitamente no Windows e, aparentemente, no Mac também, mas não consigo fazê-lo funcionar no Kubuntu sem a sobreposição de resultados distorcidos. Eu tentei lançar o aplicativo Java com o OpenJDK incluído e com o Java 8 da Oracle.

Aqui está uma foto:

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(); } } }

Encontrei a documentação no site da Oracle para testar a transparência suportada em um determinado sistema e executei os testes em minha máquina Windows. Todos os três testes retornam true, mas no Kubuntu apenas os PerPixel retornam true, a translucência uniforme retorna false.

Aqui está uma foto:

Aquiestáocódigousado:

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); } }     
por xekon 25.01.2017 / 15:42

0 respostas