2

我知道有一种方法可以扩展 JLabel 以绘制 3D 边框和一种绘制圆形边框的方法,但是您如何同时获得这两者?这是我的代码

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);
4

2 回答 2

3

LineBorder与圆角或TextBubbleBorder.

于 2012-06-29T09:46:31.597 回答
1

您参考此代码来创建圆角 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);
    }
}
于 2012-06-29T09:57:13.310 回答