JLabel topCap = new JLabel (" Top Caption");
txtTop = new JTextField("Enter top Caption here");
topCaption = new JLabel("", JLabel.CENTER);
viewerWindow.add(topCaption, BorderLayout.NORTH);
JLabel bottomCap = new JLabel (" Bottom Caption");
txtBottom = new JTextField("Enter Bottom Caption here");
bottomCaption = new JLabel("",JLabel.CENTER);
viewerWindow.add(bottomCaption,BorderLayout.SOUTH);我有另一个代码块,当用户在JTextField中输入文本并按下update JButton时,它将显示给JFrame。除下划线外,所有样式(斜体和粗体)都能很好地工作。我到处查找,在堆栈溢出上发现了一段代码,但这也没有帮助。如果您想知道,这是一行没有工作的代码:
JLabel label = new JLabel("Underlined Label");
Font font = label.getFont();
Map attributes = font.getAttributes();
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
label.setFont(font.deriveFont(attributes));我完全糊涂了,有人知道我该怎么做吗?或者至少我该查哪一门课?谢谢
发布于 2016-04-10 02:15:50
您必须从awt导入TextAttribute。
java.awt.font.TextAttribute;您可以使用HTML来下划线。但是为了比HTML更快地呈现,你应该坚持你的方法。
JLabel.setText("<HTML><U>Underlined Text</U></HTML>");发布于 2016-04-10 02:02:34
您可以很容易地在JLabel中使用HTML。举个例子,你可以这样做。
JLabel label=new JLabel();
label.setText("<html><u>Underlined Label</u></html>");https://stackoverflow.com/questions/36524796
复制相似问题