Long time, no write. I’m attempting to write some code that utilizes a transparent
window/background, but need opaque objects to be imposed over the Desktop image.
This code works for the transparent window, but I can’t seem to get the objects to
appear. From what I gather, " frame.setOpacity(0.0f); " over-rides any fill(), tint(),
alpha() command in the draw() function.
I also need to refresh the draw() function (ie: clear()?) , but if I add:
background (0, 0);
or
background (0, 0, 0, 0);
The window background goes solid black.
Any tips. links, hints, code suggestions would be appreciated!
Then just make it background(255); you can control the color of the background. My opinion is that you may have trouble getting the graphics to be opaque. It seems to me that anything you stick in a transparent window is going to be transparent (but I could be wrong about that).
An alternate approach is to use your own JFrame and add a JPanel for drawing with java’s calls. The following code will display opaque graphics in a transparent window.
//https://kodejava.org/how-do-i-create-undecorated-frame/
/* Disables or enables decorations for the frame. By setting undecorated to true we
* will remove the frame's title bar including the maximize, minimize and close icons.
* After the frame's title bar has been removed we need to close out the frame with
* our own button (may also use cmd-Q). Drawing is achieved by adding a panel component.
*/
import javax.swing.*;
import java.awt.*;
int radius = 50;
class GPanel extends JPanel {
GPanel() {
}
void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor (Color.BLACK);
g.fillOval(getWidth()/2 - radius, getHeight()/2 - radius, radius * 2, radius * 2);
}
}
void setup() {
surface.setVisible(false);
JFrame frame = new JFrame();
frame.setBounds(0,0,displayWidth,displayHeight);
frame.setLayout(null);
frame.setUndecorated(true);
frame.setBackground(new Color(0,0,0,0));
frame.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", true);
// *** Button *** //
JButton btn = new JButton("Close Me");
btn.setBounds(200,30,100,30);
btn.addActionListener(e -> System.exit(0));
frame.add(btn);
// *** Panel *** //
JPanel panel = new GPanel();
panel.setBounds(80, 60, 250, 250);
panel.setBackground(new Color(0,0,0,0));
panel.setBorder(BorderFactory.createEmptyBorder());
frame.add(panel);
// *** Label *** //
JLabel label = new JLabel("Drag Me");
label.setBounds(310,30,150,30);
frame.add(label);
frame.setVisible(true);
}
That’s essentially what I found in another thread. I’ll link/post it here and edit my OP so that others can learn.
This library has several functions, and just seeing more from what you posted.
I’ll just need to test with mouse behaviours. There’s a library called Mouse Listener that I’ve searched. As long as the objects can be manipulated with the mouse, this seems like the solution!