[英]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.