作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码如下:
这是用于根据搜索创建 JTable
的代码。
public void myMethod(){
table_6 = new JTable(dataModel);
JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBounds(16, 170, 1000, 300);
frame.getContentPane().add(scrollPane);
scrollPane.setViewportView(table_6);
scrollPane.setVisible(true);
table_6.setFillsViewportHeight(true);
table_6.getTableHeader().setReorderingAllowed(false);
table_6.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
table_6.getColumnModel().setColumnSelectionAllowed(false);
table_6.getTableHeader().setResizingAllowed(false);
}
最佳答案
问题是要么提供支持渲染相关语言字形的Font
,要么在系统上找到兼容的字体。
后者的示例,适用于 native (安装了 250 种字体)。
注意:不要只选择其中一种字体。它可能在用户的计算机上不可用。
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class GujaratiText {
private JComponent ui = null;
String text = "તરસ્યો કૂતરો સાદડી પર બેસે છે";
GujaratiText() {
initUI();
}
public void initUI() {
if (ui!=null) return;
ui = new JPanel(new GridLayout(0,2,10,4));
ui.setBorder(new EmptyBorder(4,4,4,4));
String[] fontFamilies = GraphicsEnvironment.
getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for(String fontFamily: fontFamilies) {
Font font = new Font(fontFamily, Font.PLAIN, 20);
if (font.canDisplayUpTo(text)<0) {
JLabel label = new JLabel(text);
label.setFont(font);
ui.add(label);
ui.add(new JLabel(fontFamily));
}
}
}
public JComponent getUI() {
return ui;
}
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception useDefault) {
}
GujaratiText o = new GujaratiText();
JFrame f = new JFrame(o.getClass().getSimpleName());
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLocationByPlatform(true);
f.setContentPane(o.getUI());
f.pack();
f.setMinimumSize(f.getSize());
f.setVisible(true);
}
};
SwingUtilities.invokeLater(r);
}
}
关于java - 如何在 JTable 单元格中显示古吉拉特语文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59854376/
我是一名优秀的程序员,十分优秀!