[英]How to make 3D rounded corner JLabel in Java?
I know there is a way to extend a JLabel to paint 3D borders and a way to paint round borders, but how do you get both? 我知道有一种方法可以扩展JLabel以绘制3D边框和一种绘制圆形边框的方法,但是如何同时获得两者? Here is my code 这是我的代码
protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRoundRect(0, 0, getWidth()-1, getHeight()-1, 25, 25);
g.fill3DRect(10, 10, 30, 30, true);
super.paintComponent(g);
使用LineBorder
圆角或的变体TextBubbleBorder
。
You refer this code to create Round Corner JLabel: 您可以参考以下代码来创建Round Corner JLabel:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class RoundedLineBorder extends JPanel {
public RoundedLineBorder() {
super(true);
setLayout(new BorderLayout());
JLabel label = new JLabel("Rounded Corners");
label.setHorizontalAlignment(JLabel.CENTER);
LineBorder line = new LineBorder(Color.blue, 2, true);
label.setBorder(line);
add(label, BorderLayout.CENTER);
}
public static void main(String s[]) {
JFrame frame = new JFrame("Rounded Line Border");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 200);
frame.setContentPane(new RoundedLineBorder());
frame.setVisible(true);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.