【问题标题】:BlueJ - GUI JTextField, how to make the corners of it round like an oval?BlueJ - GUI JTextField,如何使它的角像椭圆一样圆?
【发布时间】:2014-05-03 05:03:37
【问题描述】:

如何使 TextField 的角变圆? 我正在使用 Javax.swing.*;

这是我的 BlueJ 代码:

inputLine = new JTextField();
inputLine.setBounds(480, 350, 150, 30);
contentPane.add(inputLine);  
inputLine.setForeground(Color.black);
inputLine.setBackground(Color.white);
inputLine.setBorder(BorderFactory.createLineBorder(Color.black));
inputLine.setFont(new Font("Tahoma", Font.BOLD, 13));
inputLine.setHorizontalAlignment(JTextField.CENTER);
inputLine.setEditable(true);
contentPane.add(inputLine);
inputLine.addActionListener(this);
inputLine.setText("ID Number");

【问题讨论】:

    标签: user-interface jtextfield rounded-corners bluej


    【解决方案1】:

    你能做的,是首先创建一个Jframe窗口。 如果您只需要一个文本字段,请使 j 框架的尺寸比首选的文本字段大小大一点。 然后,将 jFrame 的布局设置为绝对。 创建一个覆盖整个屏幕 Jframe 的 Jlabel。 仅在此步骤之后创建文本字段。 然后在 j 框架中的首选位置创建文本字段。 为背景设计一个图形/图片,并将背景jLabel的图标设置为您设计的图形。 您设计的图形中必须有一个圆角矩形图片,并且文本字段必须准确定位在其顶部。 完成后将文本字段的不透明度设置为 0.0。这应该很好用......

    JFrame frame = new JFrame("FrameDemo");
    jframe.setPreferredSize(new Dimension(x, y));
    
    [please add the other methods to create a jframe window...these are only the basic commands]
    
    pane.setLayout(null);//makes it an absolute layout so that it does not reshape itself
    

    frame.setVisible(true); 完成此操作后,设计您的图形。 然后: 将其导入到当前工作目录中,该目录已写入该程序。 然后: 在 jFrame 中创建一个 jLabel。

     JLabel label1 = new JLabel("JLabel Set Icon Example.");
    

    将其图标设置为您设计的图形。

    label1.setIcon(new ImageIcon("full path of the image _ with the proper file extension"));
    

    然后

    textField = new JTextField(desired value);//please add the desired value into the brackets
    
    //set its location and all the other thing that are required
    

    将 textField 的位置设置在图形中圆角矩形的正上方。

    然后:

    textField.isOpaque("false");
    
    jTextField1.setBorder(null);//this should work
    

    然后你去...用户会认为 textField 是一个圆角矩形,但实际上它就像一个具有透明背景的矩形...

    如果有任何问题,请告诉我。 谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多