EDIT:
I DO the same thing here but problem does not occur.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
public class MainFrame extends JFrame implements KeyListener {
static long start;
MyPanel right, left;
public MainFrame() {
}
public void go(){
setUndecorated(true);
setLocation(0, 0);
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setSize(screenSize);
addKeyListener(this);
setLayout(new GridLayout(1,0));
Border b = BorderFactory.createLineBorder(Color.black, 4);
Border b1 = BorderFactory.createLineBorder(Color.blue, 4);
right = new MyPanel();
left = new MyPanel();
right.setBorder(b); left.setBorder(b1);
add(left);add(right);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void update() {
left.update();
right.update();
}
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getKeyCode() == KeyEvent.VK_ESCAPE)
System.exit(1);
else if (arg0.getKeyCode() == KeyEvent.VK_RIGHT){
start = System.currentTimeMillis();
update();
}
}
@Override
public void keyReleased(KeyEvent arg0) {}
@Override
public void keyTyped(KeyEvent arg0) {}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MainFrame().go();
}
});
}
}
import java.awt.Graphics;
import javax.swing.JPanel;
public class MyPanel extends JPanel {
MyPanel(){
super();
}
public void update(){
repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
System.out.println(System.currentTimeMillis() - MainFrame.start);
}
}
First of all I want to say that I’ve prepared little example which suppose to show my problem but the problem didn’t occured in this example code it is only in the original program. I know it is horrible to read but it will help a lot, because problem is in exact particular place and you don’t need to understand rest of the code or even polish only a few lines.
- GlowneOkno is main class with a main method which starts it all.
- Glowne okno is KeyListener and Extends JFrame it contains 3 extended JPanels: MapaPanel, InfoLiniaPanel, KursPanel.
- When you press “right arrow” on keyboard it suppose to run akutalizuj(it means update) method which calls akutalizuj method(update method) in those 3 extended JPanels. In those methods there is repaint() called.
- I used static long start in class GlowneOkno to see when the method GlowneOkno:Aktualizuj is called and then I println(currentTime – GlowneOkno.start) in paint method() from InfoLiniaKurs(this is that one where the time is displayed -> you will see). And this interval is enermous it is so slow, I don’t know why, if I block in method akutalizuj Mapa Panel
I know this is big thing I am asking, but this is fith day I can’t find reason and I am unable to form question and put there everything you should know without giving all project in Eclipse and I have like 5 more hours.
Program works in 1680 x 1050
Copyrights Robert Kilar 2012 ; ) But if you wanna use it somehow just ask me. I will be glad to help.
The main main is in GlowneOkno class.
ESC to close the app.

Take a long hard look at each individual step required to do a repaint.
InfoLinePaneneeds to render the text and time. While this itself is not a difficult process, you could consider offloading some of it to a buffered image instead, cause lets face it, only the time changes. When the other details change, you could invalidate the buffer and repaint it again.mapaPanelwithout any consideration as to whether it needs to changed or notImage loading and scaling is expensive. You should consider caching these results if memory allows. Scaling is best achieved in the background. Use a low quality to scale to start with and offload the high quality scale to a separate
threadConsider what actually changes. Render everything that doesn’t change (often) to buffer instead.