我试图用带有一些非ASCII字符作为标题的按钮制作一个gui。 (特别是∧,∨和))我正在使用" \ u2227"等字符串。要做到这一点,因为试图使用"∧"给我带来麻烦。我做了一个小测试GUI(在.txt文件中编写所有代码并在终端中编译它)以查看它是否有效并且确实如此。不幸的是,我的gui太复杂了,我不能手动编写它,所以我使用的是Eclipse的WindowBuilder。当我尝试在Eclipse中创建相同的按钮时,按钮会显示该符号(□)。如果我在eclipse之外运行eclipse生成的代码,这个问题仍然存在,所以代码必定有问题,而不仅仅是eclipse错误。我不能为我的生活弄清楚这里发生了什么。
有谁知道如何解决这个问题?
测试代码(工作):
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class IncDecPanel extends JPanel implements ActionListener
{
public TestPanel()
{
incButton = new JButton("\u2227");
}
}
Eclipse生成的代码(Button有错误的符号)我从1000多行中删除它只显示相关代码,但即使只运行此部分,问题仍然存在。
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import java.awt.GridBagConstraints;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTabbedPane;
import java.awt.Insets;
import java.awt.CardLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.datatransfer.*;
import java.awt.Toolkit;
import java.awt.Font;
public class Test {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Test window = new Test();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Test() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 350, 361);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new CardLayout(0, 0));
JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
frame.getContentPane().add(tabbedPane_1, "name_7199196968440");
JPanel logicPanel = new JPanel();
tabbedPane_1.addTab("Logic", null, logicPanel, null);
GridBagLayout gbl_logicPanel = new GridBagLayout();
gbl_logicPanel.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_logicPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_logicPanel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
gbl_logicPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
logicPanel.setLayout(gbl_logicPanel);
JButton button_1 = new JButton("\u2227");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button_1.setFont(new Font("Arial", Font.PLAIN, 16));
GridBagConstraints gbc_button_1 = new GridBagConstraints();
gbc_button_1.insets = new Insets(0, 0, 5, 5);
gbc_button_1.gridx = 5;
gbc_button_1.gridy = 2;
logicPanel.add(button_1, gbc_button_1);
}
}