For some reason, when I run "frame.setBackground(new Color(1.0f,1.0f,1.0f,0.0f));", then change my button's icon and repaint (even with paintImmediately) the icon of my button refuses to change. Just commenting out that line has it working again, but I kinda want that to work.
public static void main (String[] args) throws Exception
{
robot = new Robot();
frame = new JDialog();
frame.setUndecorated(true);
frame.setSize(59,61);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
int x = (int) rect.getMaxX() - frame.getWidth() - 17;
int y = (int) rect.getMaxY() - frame.getHeight() - 40;
frame.setLocation(x, y);
frame.setAlwaysOnTop(true);
frame.setBackground(new Color(1.0f,1.0f,1.0f,0.0f));
panel = new JPanel(new BorderLayout());
panel.setBackground(new Color(1.0f,1.0f,1.0f,0.0f));
frame.add(panel);
InputStream in = HelloWorld.class.getResourceAsStream("/Working/mic2.png");
notRecording = new ImageIcon(ImageIO.read(in));
in = HelloWorld.class.getResourceAsStream("/Working/mic3.png");
recording = new ImageIcon(ImageIO.read(in));
button = new JButton(notRecording);
button.setContentAreaFilled(false);
button.setBorder(BorderFactory.createEmptyBorder());
panel.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
try
{
record();
}
catch(Exception ex)
{
ex.printStackTrace();
System.out.println("Exception");
}
}
});
frame.setVisible(true);
}
When I later run
button.setIcon(recording);
button.paintImmediately(button.getBounds());
Nothing happens.
Edit: I've read over the other thread, and checked the answer they provided, but I can't seem to find any other source that verifies SWING can't handle alpha values, and in fact most sources recommend it. Additionally, calling setOpaque according to setOpaque(true/false); Java seems to imply that using setOpaque is a much more complex concept than just transparency. Additionally, replacing setBackground with setOpaque doesn't work, so I don't think the thread should be closed due to the other thread covering a similar material.
Here's an example of what isn't working for me. In theory, this would leave just the text, or at least only the section that the button occupies of the dialog remaining visible, with the rest not opaque.
import javax.swing.*;
import java.awt.*;
public class RunnableExample
{
public static void main(String[] args)
{
JDialog dialog = new JDialog();
dialog.setUndecorated(true);
dialog.setSize(59,61);
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
dialog.setAlwaysOnTop(true);
dialog.getRootPane().setOpaque(false);
JPanel panel = new JPanel();
panel.setOpaque(false);
dialog.add(panel);
JButton button = new JButton("test");
button.setContentAreaFilled(false);
button.setBorderPainted(false);
button.setOpaque(false);
panel.add(button);
dialog.setVisible(true);
}
}