Answer the question
In order to leave comments, you need to log in
How to properly style a JTextField?
There is a transparent window.
package ru.alexp.tools;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JFrame;
public class InputFrame extends JFrame {
private static InputFrame instance;
private final ConsoleInputPanel inputPanel = new ConsoleInputPanel();
public InputFrame() {
final Dimension dim = getToolkit().getScreenSize();
setSize(500, 80);
setLocation(dim.width - getWidth() - 50, dim.height - getHeight() - 200);
setUndecorated(true);
setBackground(new Color(255, 255, 255, 0));
setType(Type.UTILITY);
add(inputPanel);
addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
repaint();
}
@Override
public void focusLost(FocusEvent e) {
repaint();
}
});
}
public static InputFrame getInputFrame() {
if (instance == null) {
instance = new InputFrame();
}
return instance;
}
}
protected void paintComponent(Graphics g) {
Graphics2D gg = (Graphics2D) g;
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gg.setColor(Color.WHITE);
gg.setFont(font);
gg.drawString(getText(), 50, 50);
}
Answer the question
In order to leave comments, you need to log in
protected void paintComponent(Graphics g) {
g.setColor(new Color(255, 255, 255, 0));
g.clearRect(0, 0, getWidth(), getHeight());
Graphics2D gg = (Graphics2D) g;
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
gg.setColor(Color.WHITE);
gg.setFont(font);
gg.drawString(getText(), 15, 50);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question