我有一个javax.swing.table.AbstractTableModel子类,它定义表列标题,如下所示: protected String[] columnNames = new String[] { "Column1", "Column2};
如何从资源包中本地化columnNames
我想从.properties文件中读取列标题,而不是在代码中对其进行硬编码,是否有更好的方法呢?
You override the getColumnName()
in order to return the localized value of the column name.
For example :
private ResourceBundle res = ResourceBundle.getBundle("MyResource");
@Override
public String getColumnName( int column ) {
return res.getString(columnNames[column]);
}
Easiest way is to modify your assignment of columnNames:
protected String[] columnNames = getColumnNames();
//...
private static String[] getColumnNames() {
return ResourceBundle.getBundle("AppResources").getString("headings").split(",");
}
Where AppResources (or AppResources_en, AppResources_fr_FR etc.) is a class that extends ResourceBundle and contains a key called "headings" which returns a comma separated list of headings.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.