在菜单中实现最近打开文件

文章作者 100test 发表时间 2007:11:21 12:14:26
来源 100Test.Com百考试题网


由于实际需要,在菜单中实现最近打开文件。从头到尾基本没有找到参考资料,基本是靠自己实现的。自从项目开发按照客户要求把Swing换成SWT之后,个人感觉麻烦了很多,主要是可参考资料变得很少,开发难度加大。但是另一方面,SWT做出来的东西的确比Swing漂亮,嘿嘿,闲话少说,下面介绍一下菜单的实现方法,中国自学编程网,www.zxbc.cn。
首先,在菜单的指定位置实现一个不可用的菜单项。
public void creatFileMenuItemUsedFile(){
pushFileUsedFile[0]= new MenuItem(subFile, SWT.PUSH).
pushFileUsedFile[0].setEnabled(false).
pushFileUsedFile[0].setText(WindowString.strMenuFileUsedFiles).//这里是在别的类中定义的菜单名
}


接着,实现需要保存路径的函数

/**
* save the file path in every element which need to save

* @param filePath
* @throws N/A
* @author tianrenliang
* @since v0.1(2007/11/07)
*/
private void getFilePath(String filePath){
//if recent file not exist
if(!(pathSave.contains(filePath)))
{
//If path number less than rule needed
if(pathSave.size() {
pathSave.add(filePath).
}
/*If path number bigger than rule needed,0delete the first
element in array list*/
else
{
// Delete the first position,the second change to the first
pathSave.remove(0).
pathSave.add(filePath).
}
}
// if recent file exist,0delete the file and add this file to the last
else
{
pathSave.remove(pathSave.indexOf(filePath)).
pathSave.add(filePath).
}
// convert the vector to string array
for(int i =0.i {
path[i] = (String)pathSave.get(i).
}
}


接着,实现设置历史文件的菜单项的函数
private void setUsedFileItem()
{
if(pushFileUsedFile[0].getText()==WindowString.strMenuFileSaveAll)
{
pushFileUsedFile[0].dispose().
}
else
{
// do nothing
}
for(int i =0.i {
if(pushFileUsedFile[i]==null)
{


相关文章


Java持久化:Preferences
在菜单中实现最近打开文件
介绍10款常用的JAVA测试工具
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛