gpt4 book ai didi

java - 如何在 JTable 单元格中显示古吉拉特语文本?

转载 作者:行者123 更新时间:2023-12-01 18:45:09 26 4
gpt4 key购买 nike

我的代码如下:

这是用于根据搜索创建 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 种字体)。

Gujarati Text

注意:不要只选择其中一种字体。它可能在用户的计算机上不可用。

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com