CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Oct 2010
    Posts
    60

    Flickering during resizing.

    When I attempt to rescale a JFrame, which has no listeners, and has two JPanels in it, the layout takes a bit to resize itself. It's not slowness due to long calculations, since there's nothing that would take that long. I've stripped out everything that has to do with the underlying simulation it's supposed to display (and replaced it with plain colors), and it still has that small lag. EDIT: Kinda forgot the main point. How can this be stopped?

    Main window:
    Code:
    package graphics;
    
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    
    import javax.swing.JFrame;
    
    /**
     * Represents the top-level window for the GUI of the logic toolkit
     * 
     * @author Henry Swanson
     * @version 1.0 Apr 3, 2011
     */
    public class MainWindow extends JFrame {
    	
    	/** Serial ID. What is this? */
    	private static final long serialVersionUID = -3880026026104218593L;
    	
    	/**
    	 * Creates a {@link MainWindow} and the {@link WorkspacePanel} and
    	 * {@link ActionPanel} within.
    	 */
    	public MainWindow() {
    		super("Logic Toolkit");
    		WorkspacePanel w = new WorkspacePanel();
    		ActionPanel a = new ActionPanel();
    		add(w, BorderLayout.CENTER);
    		add(a, BorderLayout.LINE_END);
    		setMinimumSize(new Dimension(400, 300));
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		pack();
    		setVisible(true);
    	}
    	
    }
    Workspace panel:
    Code:
    package graphics;
    
    
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    
    import javax.swing.JPanel;
    
    /**
     * The panel where all the gates are shown.
     * 
     * @author Henry Swanson
     * @version 1.0 Apr 3, 2011
     */
    public class WorkspacePanel extends JPanel {
    	
    	/** Serial ID. What is this? */
    	private static final long serialVersionUID = 6634247456369380795L;
    	
    	/**
    	 * Creates a {@link WorkspacePanel}.
    	 */
    	public WorkspacePanel() {
    		super(null);
    		setPreferredSize(new Dimension(400, 300));
    	}
    	
    	@Override
    	public void paintComponent(Graphics g) {
    		super.paintComponents(g);
    		Graphics2D g2d = (Graphics2D) g;
    		g2d.setColor(Color.GREEN);
    		g2d.fillRect(0, 0, 1024, 1024);
    	}
    }
    Action panel:
    Code:
    package graphics;
    
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    
    import javax.swing.JPanel;
    
    /**
     * The panel where buttons for actions such as adding and removing gates are.
     * 
     * @author Henry Swanson
     * @version 1.0 Apr 3, 2011
     */
    public class ActionPanel extends JPanel {
    	
    	/** Serial ID. what is this? */
    	private static final long serialVersionUID = 9139567862742794039L;
    	
    	/**
    	 * Creates a {@link ActionPanel}.
    	 */
    	public ActionPanel() {
    		super(null);
    		setPreferredSize(new Dimension(100, 300));
    	}
    	
    	@Override
    	public void paintComponent(Graphics g) {
    		super.paintComponents(g);
    		Graphics2D g2d = (Graphics2D) g;
    		g2d.setColor(Color.CYAN);
    		g2d.fillRect(0, 0, 1024, 1024);
    	}
    }
    Last edited by henryswanson; April 7th, 2011 at 06:31 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured