如何将这样的内容添加到我的项目中? 看到这条白线几乎是一个盒子,哈哈,类似这样的东西:P
最佳答案
白框看起来像 TitledBorder
,在本例中与 LineBorder
结合使用.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
class TitledBorderDemo implements Runnable {
public static void main(String[] args) {
SwingUtilities.invokeLater(new TitledBorderDemo());
}
@Override
public void run() {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setBackground(Color.gray);
panel.setBorder(new TitledBorder(new LineBorder(Color.white), "Title"));
panel.add(new JButton("Button"));
panel.add(new JLabel("Label"));
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
另请参阅How to Use Borders .
关于java - 拳击什么的。绘制矩形相关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30417559/