java windows界面感官下JFileChooser的显示问题

faith瑞诚 2012-06-14 11:34:25
我在windows界面感官下创建的JFileChooser,显示有点点小问题,最上面的“向上一层”、“创建新的文件夹”等几个按钮显示不出来,不知道是什么原因,求高手解答,首先说明,我的系统是Windows 7旗舰版的,如果把设置感官界面的语句取消,界面显示完全是正常的,下面是我的代码:

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
public class JFileChooserTest extends JFrame{
public JFileChooserTest()
{
super();
// 使用Windows的界面风格
try
{
// 是windows
if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1)
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
} catch (Exception e)
{
System.out.println("设置界面感官异常!");
e.printStackTrace();
}
setTitle("JFileChooserTest");
setBounds(100,100,350,150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
final JLabel label = new JLabel();
button.addActionListener(new ActionListener(){ //监听事件
public void actionPerformed(ActionEvent e){
JFileChooser fileChooser = new JFileChooser(); //对话框
int i = fileChooser.showOpenDialog(getContentPane()); //opendialog
if(i==JFileChooser.APPROVE_OPTION) //判断是否为打开的按钮
{
File selectedFile = fileChooser.getSelectedFile(); //取得选中的文件
label.setText(selectedFile.getPath()); //取得路径
}
}
});
getContentPane().add(button,BorderLayout.NORTH); //布局处理
getContentPane().add(label,BorderLayout.CENTER);
button.setText("上传");
}
public static void main(String[] args) {
JFileChooserTest jFileChooserTest = new JFileChooserTest();
jFileChooserTest.setVisible(true);
}
}
...全文
207 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ql664512514 2013-08-13
  • 打赏
  • 举报
回复
楼主问题解决没?
nj_dobetter 2012-06-17
  • 打赏
  • 举报
回复
我也遇到了同样的问题,几个按钮显示不出来。估计是JRE和Windows7配合的问题。
jlu_lamp_lamp 2012-06-15
  • 打赏
  • 举报
回复
我运行起来没有问题,我是win7旗舰版
把if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1)
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
去掉就是java界面的,加上就是win7本身的
你看看是不是你系统什么组件没有装的问题

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧