I am in the process of writing a program which pings a server and returns a value.
I have been trying to overlay the ping to a JFrame, where a JLabel displays the ping in a transparent window.
However, every time I call the method DrawOverlay()
, the JLabel simply redraws on top of the previously drawn label.
For context, DrawOverlay()
is called from another class, PingTest
.
void DrawOverlay(String ping)
{
JLabel lbl_ping = new JLabel(ping);
lbl_ping.removeAll();//attempts at clearing the previously drawn label
lbl_ping.revalidate();
lbl_ping.repaint();
if (!frame.isUndecorated())
{
frame.setUndecorated(true);
}
frame.setFocusableWindowState(false);
frame.setBackground(new Color(0, 0, 0, 0));
frame.setAlwaysOnTop(true);
frame.getRootPane().putClientProperty("apple.awt.draggableWindowBackground", false);
frame.getContentPane().setLayout(new java.awt.BorderLayout());
lbl_ping.setFont(new Font("serif", Font.PLAIN, 48));
lbl_ping.setForeground(Color.WHITE);
lbl_ping.setText(ping);
frame.add(lbl_ping);
frame.setVisible(true);
frame.pack();
}
Is there any way to redraw a JFrame or JLabel to remove the previous data?