因为我的JScrollPane里有很多的JButton在拉滚动条时,有很明显的刷新跟不上,就是被拉出来的新画面会出现白的部分。
怎么能解决呀!!
怎么能解决呀!!
解决方案 »
- java中输入一个数,如何判断此数是不是6位数,在线等
- 只看楼主 回复 标题要长 求助求助求助 Font类中的 getStringBounds()
- 大家是如何理解内部类的? JAVA之父为什么要设计内部类出来?
- Jsp的一个小问题
- 请教eclipse功能菜单操作高手,怎么将一个接口用菜单中的某一个功能进行implements.感谢
- java utf-8转ansi问题
- 有argments的console程序的usage应该怎么写?
- java在的MO开发中如何设置时间参数?
- JBuilder7的s/n或者Active File
- applet无法在IE6中执行
- 请问在页面打开一个url连接,该连接是一个pdf文件,如何通过后台程序保存
- 如何监听某一个文件夹下有没有文件写入而后删除了该文件?
getContentPane().setLayout(null);
this.setBackground(Color.BLACK);
this.setLocale(new java.util.Locale("sq"));
getContentPane().setForeground(new java.awt.Color(0,128,255));
this.setVisible(false);
{
devicePanel = new JPanel();
getContentPane().add(devicePanel);
devicePanel.setBackground(Color.white);
devicePanel.setLayout(null);
devicePanel.setName("devicePanel");
devicePanel.setBounds(0, 0, deviceWidth, deviceHeight);
{
jLabel1 = new JLabel();
devicePanel.add(jLabel1);
jLabel1.setText(devicetitleString);
jLabel1.setBounds(7, 7, deviceWidth-10, deviceHeight-10);
jLabel1.setFont(new java.awt.Font("MS Gothic",0,14));
}
}
{
headerPane = new GanttHeader();//JScrollPane
headerPane.setBackground(Color.white);
headerPane.setBounds(deviceWidth, 0, width-deviceWidth-17, height);
}
{
itemPane = new GanttItem();//JScrollPane
itemPane.setBounds(0, deviceHeight, width, height-deviceHeight-17);
}
{
ganttChart = new GanttChart();//JScrollPane
getContentPane().add(ganttChart);
getContentPane().add(itemPane);
getContentPane().add(headerPane);
ganttChart.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS );
ganttChart.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
ganttChart.setBounds(deviceWidth-1,deviceHeight,width-deviceWidth,height-deviceHeight);
JScrollBar bar = ganttChart.getHorizontalScrollBar();
JScrollBar bar1 = ganttChart.getVerticalScrollBar();
bar.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{ JScrollBar bar3 = headerPane.getHorizontalScrollBar();
int a=e.getValue();
bar3.setValue(a);
bar3.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e) {
headerPane.repaint();}
});
repaint();
}
});
bar1.addAdjustmentListener(new AdjustmentListener()
{
public void adjustmentValueChanged(AdjustmentEvent e)
{
JScrollBar bar2 = itemPane.getVerticalScrollBar();
int a=e.getValue();
bar2.setValue(a);
bar2.addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e) {
itemPane.repaint();}
});
repaint();
}
});
}
GanttChart代码protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.fillRect(0, 1,GanttChart.height,GanttChart.chartCount*GanttChart.chartheight);
g.setColor(Color.YELLOW);
g.setFont(new Font("", Font.BOLD, 12));
int xx;
JButton jButton=null;
for(int i=1;i<=GanttChart.chartCount;i++)
{
xx = i * GanttChart.chartheight;
GanttChart.chartheight,GanttHeader.titlePanelWidth,xx);
jButton=new JButton();
jButton.setSize(this.getSize().width/2,10);
jButton.setBounds(50,xx-35,GanttHeader.titlePanelWidth/2,15);
this.add(jButton);
g.drawLine(0,xx,GanttHeader.titlePanelWidth,xx);
}
}
你应该把所有Button的创建放在这个面板的构造函数中。让paintComponent只是去填充颜色而已。
嗯 有道理· 你就是想產生多個jbutton 這段代碼 完全可以放到外面~ 和paint沒啥關系·