sách gpt4 ai đã đi

java - 禁用 JTextField 的边框

In lại 作者:行者123 更新时间:2023-12-01 13:12:23 29 4
mua khóa gpt4 Nike

有没有办法在不丢失边框的情况下禁用 JTextField?基本上我有几个文本字段,其中一些是启用的,一些是禁用的。然而,残疾人是没有国界的。我希望所有文本字段看起来都一样,无论它们是启用还是禁用。有什么办法可以做到这一点吗?

感谢您的回答

1 Câu trả lời

在此计划中您可以找到解决方案

  nhập java.awt.*;  
nhập java.awt.event.*;
nhập javax.swing.*;

public class DressingUpComponents
{
JTextField disabled,
normal;
JLabel label;

public DressingUpComponents()
{
configureDisabledTextField();
normal = new JTextField("hello world");
configureLabel();
}

private void configureDisabledTextField()
{
disabled = new JTextField("hello world");
disabled.setEnabled(false);
Color bgColor = UIManager.getColor("TextField.background");
disabled.setBackground(bgColor);
Color fgColor = UIManager.getColor("TextField.foreground");
disabled.setDisabledTextColor(fgColor);
disabled.setBorder(BorderFactory.createEtchedBorder());
}

private void configureLabel()
{
label = new JLabel("hello world");
label.setBorder(BorderFactory.createEtchedBorder());
label.setOpaque(true); // required for background colors
label.setBackground(UIManager.getColor("TextField.background"));
label.setFont(UIManager.getFont("TextField.font"));
}

public static void main(String[] args)
{
DressingUpComponents dup = new DressingUpComponents();
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = f.getContentPane();
cp.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weighty = 1.0; // allow vertical dispersion
gbc.gridwidth = GridBagConstraints.REMAINDER; // single column
cp.add(dup.disabled, gbc);
cp.add(dup.normal, gbc);
cp.add(dup.label, gbc);
f.setSize(200,200);
f.setLocation(200,200);
f.setVisible(true);
}
}

关于java - 禁用 JTextField 的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748399/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com