I have an application that displays 10-50 images at a time on my frame, with boxes around them. I can drag the images and place them in a new location in the array, and the frame will update the whole time. The reason I'm making this post is because my 3440x1440 monitor makes this program lag, and my old 1920x1080 didn't lag at all.
Here's a gif showing what I'm talking about: https://gfycat.com/InferiorFrenchArachnid
and here's my code for drawing the images and the boxes surrounding them to the frame:
public void paintComponent(Graphics g){
super.paintComponent(g);
if (model.getCarPath() == null){
viewImage = createImage(1000,1000);
viewGraphics = viewImage.getGraphics();
viewGraphics.setColor(color);
viewGraphics.fillRect(0, 0, 1000, 1000);
}
try{
if (model.getCarPath() != null){
if(viewImage==null){
viewImage = createImage(1000,1000);
viewGraphics = viewImage.getGraphics();
}
viewGraphics.setColor(color);
viewGraphics.fillRect(0, 0, 1000, 1000);
viewGraphics.setColor(Color.blue);
for (int i = 0; i < model.getPictureArray().size()-1; i++){
//draw the images
viewGraphics.drawImage(x,y,width,height, this);
}
// draws the selected picture over top of the rest
viewGraphics.drawImage(model.getSelected().getImage(), (int)x,
(int)y, (int)width,
(int)height, this);
if (model.doesLineExist() == true){
// draws the line next to the pictures to show where the picture will be dropped
// when the mouse is released
viewGraphics.fillRect((int)model.getLine().getX(), (int)model.getLine().getY(), 5,
(int)model.getLine().getHeight());
}
}
} catch (Exception e){ }
g.drawImage(viewImage, 0, 0, this);
}
Without posting the entirety of my code, I think this encompasses the least efficient part. Is there anything you see that I can change that will stop the program from lagging?