繁体   English   中英

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

[英]How to display Gujarati text in the JTable cell?

我的代码是这样的:

这是用于基于搜索创建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 ,要么在系统上找到兼容的字体。

后者的示例,对于这台机器(安装了 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);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM