在这两个岗位@iMohammad连接,
增加/减少内部使用的JButton textarea的字体大小和
上一个JButton的Java点击时更改字体样式 ......,我面临着从来到真是好笑问题JComboBox通过传递setPrototypeDisplayValue作为一个参数JComboBox's size上屏幕
请问我如何JComboBox动态调整大小,取决于Font我在sscce中尝试的另一个JComponents的正确工作
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ComboBoxFontChange extends JFrame {
private static final long serialVersionUID = 1L;
private JComboBox cbox = new JComboBox();
private JTextField tfield = new JTextField("Change");
private JLabel label = new JLabel("Cash");
private JButton button = new JButton("++ Font");
private JTextField text;
private JPanel panel = new JPanel();
public ComboBoxFontChange() {
super("Combo Box Font change"); …Run Code Online (Sandbox Code Playgroud) 我正在使用Java创建一个便利贴应用程序.
我想做什么:
我想在textArea每次点击增加大小时增加文本的大小.我会明白如何做相反的事情.
短代码:
JButton incButton = new JButton("+");
fontFrame.add(incButton);
incButton.addActionListener(new fontIncAction());
JButton DecButton = new JButton("-");
fontFrame.add(DecButton);
//textArea.setFont( Font("Serif", Font.PLAIN, fz));
}
}
private class fontIncAction implements ActionListener{
public void actionPerformed(ActionEvent e){
textArea.setFont(new Font("Serif",Font.PLAIN,20));
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用构建HTML编辑器JEditorPane,但是我遇到了一些与Foreground Actions不一致的性能问题.我的编辑器的简化版本有三个动作:将字体颜色更改为红色或蓝色,或更改字体大小.现在使用以下testFile.html文件:
<html>
<head><title>Title</title></head>
<body link="#0000FF" bgcolor="white">
<font size="4" face="arial" color="black">Some test text</font>
<font size="3" face="arial" color="black">Some new test text </font>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
有时我可以在编辑器中突出显示一些文本,然后按红色或蓝色按钮,它可以正常工作,即它会改变颜色.在其他场合(即如果我关闭我的JVM并再次启动它)颜色将不会改变直到我StyledEditorKit.FontSizeAction在相同的文本上应用.
我是如何应用的ForegroundActions?或者这可能是一些Java bug?
代码如下:
public class EditorTest extends JFrame{
private JEditorPane editorPane;
public EditorTest()
{
editorPane = new JEditorPane();
editorPane.setContentType("text/HTML");
getContentPane().add(editorPane, BorderLayout.CENTER);
editorPane.setEditorKit(new HTMLEditorKit());
Action a = new StyledEditorKit.ForegroundAction("RedColor", Color.RED);
editorPane.getActionMap().put("RedColor", a);
JToolBar bar = new JToolBar();
JButton button = new JButton("blue");
button.addActionListener(new StyledEditorKit.ForegroundAction (
"set-foreground-red", Color.blue));
bar.add(editorPane.getActionMap().get("font-size-12")).setText("12");
bar.add(button);
bar.add(editorPane.getActionMap().get("RedColor")).setText("Red");
getContentPane().add(bar, …Run Code Online (Sandbox Code Playgroud)