请教一个SWING闪烁的问题﹐恳请大家帮帮忙(在线等候) To binbin2000(binbin):Swing默认不是有用双缓冲吗?好象只有JPanel才有isDoubleBuffered的开关﹐我是在一个JInternalFrame中显示JTable﹐好象没有双缓冲的开关呀? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的代码我用了,是不是你的表格太大了,我改成(randomModel(100,100,100))以后运行一点问题都没有呀(1.4.1)! 不闪烁。我的配置:win2k jdk1.4.2 eclipse//倒是那个大Table搞得我内存溢出了~~~~~@@ to HurricanDavidLiu(阿文) 是有问题的﹐和1.3比较以下就很明显﹐有一点延时的感觉paulone(雪刃堂)不知道你运行JDK的DEMO中的SwingSet2的JScrollPane怎么样? 快速拖动滚动条就有问题 大家都没问题吗?我用JB7,自带JDK1.3.1﹐加了JDK1.4﹐同样的程序﹐差别很明显。1.4的Scroll拖动时会象水波一样﹐严重的话整个屏幕都会闪﹐我有测试和计算机速度有关﹐但1.3很好。程序改了一点﹐肯定有用DoubleBufferimport java.awt.event.WindowEvent;import java.awt.BorderLayout;import javax.swing.*;import javax.swing.table.*;public class Cilent { public static void main(String[] s){ JFrame frame=new JFrame(); JPanel panel=new JPanel(new BorderLayout(),true);//use doubleBuffer frame.getContentPane().add(panel,BorderLayout.CENTER); JTable table=new JTable(randomModel(100,100,1000000)); table.setAutoResizeMode(0); panel.add(new JScrollPane(table)); frame.setSize(800,600); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private static TableModel randomModel(int rowNum,int colNum,int base){ java.util.Date date=new java.util.Date(); TableModel tm=new DefaultTableModel(rowNum,colNum); for(int i=0;i<rowNum;i++){ for(int j=0;j<colNum;j++){ double data=Math.random()*base; tm.setValueAt(String.valueOf(data),i,j); } } return tm; }} 嗯,是有一点延迟。但是没感觉闪烁。那个table太大,我给改小了一点才可以运行。不知道是不是因为这个才不会出现楼主说得现象了 注意tableheader, 明显会错位﹗如果机器快就多加几行﹐切换JDK1.3﹐有没有差别? 改用IFrame的例子:import java.awt.event.WindowEvent;import java.awt.BorderLayout;import javax.swing.*;import javax.swing.table.*;public class Client { public static void main(String[] s){ JFrame frame=new JFrame(); JDesktopPane desktop=new JDesktopPane(); frame.setContentPane(desktop); JInternalFrame iframe=new JInternalFrame("",true,true,true,true); desktop.add(iframe); JPanel panel=new JPanel(new BorderLayout(),true);//use doubleBuffer iframe.setContentPane(panel); JTable table=new JTable(randomModel(100,100,1000000)); table.setAutoResizeMode(0); panel.add(new JScrollPane(table)); iframe.setSize(640,480); iframe.setVisible(true); frame.setSize(800,600); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private static TableModel randomModel(int rowNum,int colNum,int base){ java.util.Date date=new java.util.Date(); TableModel tm=new DefaultTableModel(rowNum,colNum); for(int i=0;i<rowNum;i++){ for(int j=0;j<colNum;j++){ double data=Math.random()*base; tm.setValueAt(String.valueOf(data),i,j); } } return tm; }} 加了renderer后更明显﹐是不是JDK1.4.2有新method呢?import java.awt.event.WindowEvent;import java.awt.*;import javax.swing.*;import javax.swing.table.*;public class Client { public Client(){ JFrame frame=new JFrame(); JDesktopPane desktop=new JDesktopPane(); frame.setContentPane(desktop); JInternalFrame iframe=new JInternalFrame("",true,true,true,true); desktop.add(iframe); JPanel panel=new JPanel(new BorderLayout(),true);//use doubleBuffer iframe.setContentPane(panel); JTable table=new JTable(randomModel(1000,100,1000000)); table.setAutoResizeMode(0); table.setDefaultRenderer(Object.class,new MyRenderer()); panel.add(new JScrollPane(table)); iframe.setSize(640,480); iframe.setVisible(true); frame.setSize(800,600); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] s){ new Client(); } private static TableModel randomModel(int rowNum,int colNum,int base){ java.util.Date date=new java.util.Date(); TableModel tm=new DefaultTableModel(rowNum,colNum); for(int i=0;i<rowNum;i++){ for(int j=0;j<colNum;j++){ double data=Math.random()*base; tm.setValueAt(String.valueOf(data),i,j); } } return tm; } class MyRenderer extends JLabel implements TableCellRenderer{ Color[] c={Color.blue,Color.cyan,Color.black,Color.yellow,Color.red,Color.darkGray,Color.gray,Color.green,Color.lightGray,Color.orange}; public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,boolean hasFocus, int row,int column) { int ic=(int)Float.parseFloat(value.toString().substring(0,1)); this.setForeground(c[ic]); this.setOpaque(true); this.setBackground(c[ic-1]); this.setText(value.toString()); return this; } }} 将JPanel panel=new JPanel(new BorderLayout(),true);该为JPanel panel=new JPanel(new BorderLayout(),false);没有任何变化﹗﹗﹗DoubleBuffer设置不正确? 楼主的电脑看来很好呢,我一运行你这段代码就提示内存溢出异常.我运行这么多程序还头一次遇到内存不足的原因.我猜试楼主给的表格数据太多了.我原来用的数据顶多只超过屏幕的三分之一,用swing用的很好,没有什么闪烁.我想时楼主的表格太大了,加上拖动滚动条的速度太快了的原因. 非常感謝 pqds(一个女农民) 那篇文章是不是 http://www.mhdn.net/p/2002-09-10/5865.html ?問題已解決TO noratong(诺拉) ﹕內存溢出應是JVM設置的問題﹐我用的是公司的破機器﹐只有RAM好點(512SDRAM)。實際運行的系統數據更多﹐20K﹑30K行。正在想怎樣分頁﹐有好方法交流一下啦﹗再次感謝 pqds(一个女农民) import java.awt.event.WindowEvent;import java.awt.*;import javax.swing.*;import javax.swing.table.*;public class Client { public Client(){ JFrame frame=new JFrame(); JDesktopPane desktop=new JDesktopPane(); frame.setContentPane(desktop); JInternalFrame iframe=new JInternalFrame("",true,true,true,true); desktop.add(iframe); JPanel panel=new JPanel(new BorderLayout(),false);//use doubleBuffer iframe.setContentPane(panel); JTable table=new JTable(randomModel(1000,100,1000000)); table.setAutoResizeMode(0); table.setDefaultRenderer(Object.class,new MyRenderer()); JScrollPane scroll=new JScrollPane(); JViewport view=new JViewport(); //view.setScrollMode(JViewport.BLIT_SCROLL_MODE); //view.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); view.setScrollMode(JViewport.SIMPLE_SCROLL_MODE); view.add(table); scroll.setViewport(view); panel.add(scroll); iframe.setSize(640,480); iframe.setVisible(true); frame.setSize(800,600); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] s){ new Client(); } private static TableModel randomModel(int rowNum,int colNum,int base){ java.util.Date date=new java.util.Date(); TableModel tm=new DefaultTableModel(rowNum,colNum); for(int i=0;i<rowNum;i++){ for(int j=0;j<colNum;j++){ double data=Math.random()*base; tm.setValueAt(String.valueOf(data),i,j); } } return tm; } class MyRenderer extends JLabel implements TableCellRenderer{ Color[] c={Color.blue,Color.cyan,Color.black,Color.yellow,Color.red,Color.darkGray,Color.gray,Color.green,Color.lightGray,Color.orange}; public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,boolean hasFocus, int row,int column) { int ic=(int)Float.parseFloat(value.toString().substring(0,1)); this.setForeground(c[ic]); this.setOpaque(true); this.setBackground(c[ic-1]); this.setText(value.toString()); return this; } }} 数据库配置和连接问题 大家帮我实现一个一个字一个输出的程序!我写的下边怎么改就对了 SAX的疑惑 java下如何调用浏览器打开网页 用什么数组存储不同的数据类型?在提取的时候不需要进行类型转换!(急) 求助:一个小程序(小弟太穷了,麻烦大侠们免费帮个忙,狂谢!) 学到java的流了,但被那些文件类型搞糊涂了! 网络编程问题,如何通过代理服务器收发短信???? 菜鸟又来了各位还好啊看看一个简单的但我想了一天的问题. 关于等待多线程结束的问题 ▆▆▆◣电脑没死机,java数据库程序就是跑不起来,怪问题!!! 关于jar命令的用法
我的配置:
win2k jdk1.4.2 eclipse
//
倒是那个大Table搞得我内存溢出了~~~~~@@
是有问题的﹐和1.3比较以下就很明显﹐有一点延时的感觉
paulone(雪刃堂)
不知道你运行JDK的DEMO中的SwingSet2的JScrollPane怎么样? 快速拖动滚动条就有问题
我用JB7,自带JDK1.3.1﹐加了JDK1.4﹐同样的程序﹐差别很明显。
1.4的Scroll拖动时会象水波一样﹐严重的话整个屏幕都会闪﹐我有测试和计算机速度有关﹐但1.3很好。
程序改了一点﹐肯定有用DoubleBuffer
import java.awt.event.WindowEvent;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.table.*;public class Cilent {
public static void main(String[] s){
JFrame frame=new JFrame();
JPanel panel=new JPanel(new BorderLayout(),true);//use doubleBuffer
frame.getContentPane().add(panel,BorderLayout.CENTER);
JTable table=new JTable(randomModel(100,100,1000000));
table.setAutoResizeMode(0);
panel.add(new JScrollPane(table));
frame.setSize(800,600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} private static TableModel randomModel(int rowNum,int colNum,int base){
java.util.Date date=new java.util.Date();
TableModel tm=new DefaultTableModel(rowNum,colNum);
for(int i=0;i<rowNum;i++){
for(int j=0;j<colNum;j++){
double data=Math.random()*base;
tm.setValueAt(String.valueOf(data),i,j);
}
}
return tm;
}
}
那个table太大,我给改小了一点才可以运行。不知道是不是因为这个才不会出现楼主说得现象了
改用IFrame的例子:
import java.awt.event.WindowEvent;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.table.*;public class Client {
public static void main(String[] s){
JFrame frame=new JFrame();
JDesktopPane desktop=new JDesktopPane();
frame.setContentPane(desktop); JInternalFrame iframe=new JInternalFrame("",true,true,true,true);
desktop.add(iframe); JPanel panel=new JPanel(new BorderLayout(),true);//use doubleBuffer
iframe.setContentPane(panel); JTable table=new JTable(randomModel(100,100,1000000));
table.setAutoResizeMode(0);
panel.add(new JScrollPane(table)); iframe.setSize(640,480);
iframe.setVisible(true);
frame.setSize(800,600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} private static TableModel randomModel(int rowNum,int colNum,int base){
java.util.Date date=new java.util.Date();
TableModel tm=new DefaultTableModel(rowNum,colNum);
for(int i=0;i<rowNum;i++){
for(int j=0;j<colNum;j++){
double data=Math.random()*base;
tm.setValueAt(String.valueOf(data),i,j);
}
}
return tm;
}
}
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;public class Client {
public Client(){
JFrame frame=new JFrame();
JDesktopPane desktop=new JDesktopPane();
frame.setContentPane(desktop); JInternalFrame iframe=new JInternalFrame("",true,true,true,true);
desktop.add(iframe); JPanel panel=new JPanel(new BorderLayout(),true);//use doubleBuffer
iframe.setContentPane(panel); JTable table=new JTable(randomModel(1000,100,1000000));
table.setAutoResizeMode(0);
table.setDefaultRenderer(Object.class,new MyRenderer());
panel.add(new JScrollPane(table)); iframe.setSize(640,480);
iframe.setVisible(true);
frame.setSize(800,600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public static void main(String[] s){
new Client();
} private static TableModel randomModel(int rowNum,int colNum,int base){
java.util.Date date=new java.util.Date();
TableModel tm=new DefaultTableModel(rowNum,colNum);
for(int i=0;i<rowNum;i++){
for(int j=0;j<colNum;j++){
double data=Math.random()*base;
tm.setValueAt(String.valueOf(data),i,j);
}
}
return tm;
} class MyRenderer extends JLabel implements TableCellRenderer{
Color[] c={Color.blue,Color.cyan,Color.black,Color.yellow,Color.red,Color.darkGray,Color.gray,Color.green,Color.lightGray,Color.orange};
public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,boolean hasFocus, int row,int column) {
int ic=(int)Float.parseFloat(value.toString().substring(0,1));
this.setForeground(c[ic]);
this.setOpaque(true);
this.setBackground(c[ic-1]);
this.setText(value.toString());
return this;
}
}
}
JPanel panel=new JPanel(new BorderLayout(),true);
该为
JPanel panel=new JPanel(new BorderLayout(),false);
没有任何变化﹗﹗﹗
DoubleBuffer设置不正确?
我想时楼主的表格太大了,加上拖动滚动条的速度太快了的原因.
那篇文章是不是 http://www.mhdn.net/p/2002-09-10/5865.html ?問題已解決TO noratong(诺拉) ﹕內存溢出應是JVM設置的問題﹐我用的是公司的破機器﹐只有RAM好點(512SDRAM)。實際運行的系統數據更多﹐20K﹑30K行。正在想怎樣分頁﹐有好方法交流一下啦﹗再次感謝 pqds(一个女农民) import java.awt.event.WindowEvent;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;public class Client {
public Client(){
JFrame frame=new JFrame();
JDesktopPane desktop=new JDesktopPane();
frame.setContentPane(desktop); JInternalFrame iframe=new JInternalFrame("",true,true,true,true);
desktop.add(iframe); JPanel panel=new JPanel(new BorderLayout(),false);//use doubleBuffer
iframe.setContentPane(panel); JTable table=new JTable(randomModel(1000,100,1000000));
table.setAutoResizeMode(0);
table.setDefaultRenderer(Object.class,new MyRenderer());
JScrollPane scroll=new JScrollPane();
JViewport view=new JViewport();
//view.setScrollMode(JViewport.BLIT_SCROLL_MODE);
//view.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
view.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
view.add(table);
scroll.setViewport(view);
panel.add(scroll); iframe.setSize(640,480);
iframe.setVisible(true);
frame.setSize(800,600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} public static void main(String[] s){
new Client();
} private static TableModel randomModel(int rowNum,int colNum,int base){
java.util.Date date=new java.util.Date();
TableModel tm=new DefaultTableModel(rowNum,colNum);
for(int i=0;i<rowNum;i++){
for(int j=0;j<colNum;j++){
double data=Math.random()*base;
tm.setValueAt(String.valueOf(data),i,j);
}
}
return tm;
} class MyRenderer extends JLabel implements TableCellRenderer{
Color[] c={Color.blue,Color.cyan,Color.black,Color.yellow,Color.red,Color.darkGray,Color.gray,Color.green,Color.lightGray,Color.orange};
public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,boolean hasFocus, int row,int column) {
int ic=(int)Float.parseFloat(value.toString().substring(0,1));
this.setForeground(c[ic]);
this.setOpaque(true);
this.setBackground(c[ic-1]);
this.setText(value.toString());
return this;
}
}
}