Java Code Examples for javax.swing.JFrame#repaint()

The following examples show how to use javax.swing.JFrame#repaint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBigLayoutModel.java    From ghidra with Apache License 2.0 9 votes vote down vote up
public static void main(String[] args) {
	final Font font = new Font("monospace", Font.PLAIN, 12);
	final JFrame frame = new JFrame();
	final TestBigLayoutModel model =
		new TestBigLayoutModel(frame.getFontMetrics(font), "AAA", BigInteger.valueOf(1000000L));
	final FieldPanel provider = new FieldPanel(model);
	IndexedScrollPane scrollPanel = new IndexedScrollPane(provider);
	Container contentPane = frame.getContentPane();
	contentPane.setLayout(new BorderLayout());
	contentPane.add(scrollPanel);
	JButton button = new JButton("Hit Me");
	button.addActionListener(e -> model.updateData(1000, 2000));
	contentPane.add(button, BorderLayout.SOUTH);
	frame.pack();
	frame.setVisible(true);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.repaint();

}
 
Example 2
Source File: SpectralMatchPanel.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This calculates the size for the export. Do not call export right after, or it won't have time
 * to update
 */
public void calculateAndSetSize() {
  int w = META_WIDTH * 3;
  int titleLineMultiplier = (int) ((boxTitlePanel.getPreferredSize().getWidth() / w) + 2);
  boxTitlePanel.setSize(w, boxTitlePanel.getHeight() * titleLineMultiplier);
  int h = (boxTitlePanel.getHeight() + (int) metaDataPanel
      .getPreferredSize().getHeight());

  JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
  frame.setSize(w, h);
  this.setSize(w, h);

  revalidate();
  repaint();

  frame.revalidate();
  frame.repaint(0, 0, 0, w, h);
}
 
Example 3
Source File: GetCurrentSkin.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Opens a sample frame under the specified skin.
 * 
 * @param skin
 *            Skin.
 */
private void openSampleFrame(SubstanceSkin skin) {
    final JFrame sampleFrame = new JFrame(skin.getDisplayName());
    sampleFrame.setLayout(new FlowLayout());
    final JButton button = new JButton("Get skin");
    button.addActionListener((ActionEvent e) -> SwingUtilities.invokeLater(
            () -> JOptionPane.showMessageDialog(sampleFrame, "Skin of this button is "
                    + SubstanceCortex.ComponentScope.getCurrentSkin(button).getDisplayName())));

    sampleFrame.add(button);

    sampleFrame.setVisible(true);
    sampleFrame.setSize(200, 100);
    sampleFrame.setLocationRelativeTo(null);
    sampleFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    SubstanceCortex.RootPaneScope.setSkin(sampleFrame.getRootPane(), skin);
    SwingUtilities.updateComponentTreeUI(sampleFrame);
    sampleFrame.repaint();
}
 
Example 4
Source File: SetRootPaneSkin.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Opens a sample frame under the specified skin.
 * 
 * @param skin
 *            Skin.
 */
private void openSampleFrame(SubstanceSkin skin) {
    JFrame sampleFrame = new JFrame(skin.getDisplayName());
    sampleFrame.setLayout(new FlowLayout());
    JButton defaultButton = new JButton("active");
    JButton button = new JButton("default");
    JButton disabledButton = new JButton("disabled");
    disabledButton.setEnabled(false);
    sampleFrame.getRootPane().setDefaultButton(defaultButton);

    sampleFrame.add(defaultButton);
    sampleFrame.add(button);
    sampleFrame.add(disabledButton);

    sampleFrame.setVisible(true);
    sampleFrame.pack();
    sampleFrame.setLocationRelativeTo(null);
    sampleFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    sampleFrame.setIconImage(new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR));

    SubstanceCortex.RootPaneScope.setSkin(sampleFrame.getRootPane(), skin);
    SwingUtilities.updateComponentTreeUI(sampleFrame);
    sampleFrame.repaint();
}
 
Example 5
Source File: ShapeBoard.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed (ActionEvent e)
{
    // Remove current panel of shapes
    getBody()
            .remove(shapesPanel);

    // Replace by panel of ranges
    getBody()
            .add(rangesPanel);

    // Perhaps this is too much ... TODO
    JFrame frame = Main.getGui()
            .getFrame();
    frame.invalidate();
    frame.validate();
    frame.repaint();
}
 
Example 6
Source File: DrawBitmaskToSurfaceTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 7
Source File: DrawBitmaskToSurfaceTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 8
Source File: DrawBitmaskToSurfaceTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 9
Source File: DrawBitmaskToSurfaceTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 10
Source File: DrawBitmaskToSurfaceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 11
Source File: DrawBitmaskToSurfaceTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 12
Source File: QueryBuilder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void doShowBusyCursor(boolean busy) {
    JFrame mainWindow = (JFrame)WindowManager.getDefault().getMainWindow();
    if(busy){
        RepaintManager.currentManager(mainWindow).paintDirtyRegions();
        mainWindow.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        mainWindow.getGlassPane().setVisible(true);
        mainWindow.repaint();
    } else {
        mainWindow.getGlassPane().setVisible(false);
        mainWindow.getGlassPane().setCursor(null);
        mainWindow.repaint();
    }
}
 
Example 13
Source File: DrawBitmaskToSurfaceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 14
Source File: FocusAfterBadEditTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    if (setup) return;
    
    try {
        focusWorks = ExtTestCase.canSafelyRunFocusTests();
        if (!focusWorks) {
            return;
        }
        
        tp = new TProperty("Dont set me!", true);
        
        tn = new TNode();
        //            PropUtils.forceRadioButtons=true;
        final PropertySheet ps = new PropertySheet();
        
        //ensure no stored value in preferences:
        ps.setCurrentNode(tn);
        sleep();
        ps.setSortingMode(PropertySheet.UNSORTED);
        
        jf = new JFrame();
        jf.getContentPane().add(ps);
        jf.setLocation(20,20);
        jf.setSize(300, 400);
        new WaitWindow(jf);
        tb = ps.table;
        
        jf.repaint();
        
        
    } catch (Exception e) {
        e.printStackTrace();
        fail("FAILED - Exception thrown "+e.getClass().toString());
    } finally {
        setup = true;
    }
}
 
Example 15
Source File: ShapeBoard.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed (ActionEvent e)
{
    // Remove panel of ranges
    getBody()
            .remove(rangesPanel);

    // Replace by proper panel of range shapes
    String rangeName = ((JButton) e.getSource()).getName();
    ShapeSet range = ShapeSet.getShapeSet(rangeName);
    shapesPanel = shapesPanels.get(range);

    if (shapesPanel == null) {
        // Lazily populate the map of shapesPanel instances
        shapesPanels.put(range, shapesPanel = defineShapesPanel(range));
    }

    getBody()
            .add(shapesPanel);

    // Perhaps this is too much ... TODO
    JFrame frame = Main.getGui()
            .getFrame();
    frame.invalidate();
    frame.validate();
    frame.repaint();
}
 
Example 16
Source File: DrawBitmaskToSurfaceTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 17
Source File: DrawBitmaskToSurfaceTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 18
Source File: GameVisualSimulationWithSocketAI.java    From microrts with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
        UnitTypeTable utt = new UnitTypeTable();
        PhysicalGameState pgs = PhysicalGameState.load("maps/16x16/basesWorkers16x16.xml", utt);
//        PhysicalGameState pgs = MapGenerator.basesWorkers8x8Obstacle();

        GameState gs = new GameState(pgs, utt);
        int MAXCYCLES = 5000;
        int PERIOD = 20;
        boolean gameover = false;
        
//        AI ai1 = new WorkerRush(utt, new BFSPathFinding());        
        AI ai1 = new SocketAI(100,0, "127.0.0.1", 9898, SocketAI.LANGUAGE_XML, utt);
//        AI ai1 = new SocketAI(100,0, "127.0.0.1", 9898, SocketAI.LANGUAGE_JSON, utt);
        AI ai2 = new RandomBiasedAI();
        
        ai1.reset();
        ai2.reset();

        JFrame w = PhysicalGameStatePanel.newVisualizer(gs,640,640,false,PhysicalGameStatePanel.COLORSCHEME_BLACK);
//        JFrame w = PhysicalGameStatePanel.newVisualizer(gs,640,640,false,PhysicalGameStatePanel.COLORSCHEME_WHITE);

        ai1.preGameAnalysis(gs, 1000, ".");
        ai2.preGameAnalysis(gs, 1000, ".");

        long nextTimeToUpdate = System.currentTimeMillis() + PERIOD;
        do{
            if (System.currentTimeMillis()>=nextTimeToUpdate) {
                PlayerAction pa1 = ai1.getAction(0, gs);
                PlayerAction pa2 = ai2.getAction(1, gs);
                gs.issueSafe(pa1);
                gs.issueSafe(pa2);

                // simulate:
                gameover = gs.cycle();
                w.repaint();
                nextTimeToUpdate+=PERIOD;
            } else {
                try {
                    Thread.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }while(!gameover && gs.getTime()<MAXCYCLES);
        
        System.out.println("Game Over");
    }
 
Example 19
Source File: POGameVisualSimulationTest.java    From microrts with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
        UnitTypeTable utt = new UnitTypeTable();
        PhysicalGameState pgs = PhysicalGameState.load("maps/16x16/basesWorkers16x16.xml", utt);
//        PhysicalGameState pgs = MapGenerator.basesWorkers8x8Obstacle();

        GameState gs = new GameState(pgs, utt);
        int MAXCYCLES = 5000;
        int PERIOD = 20;
        boolean gameover = false;
        
//        AI ai1 = new RandomAI();
//        AI ai1 = new WorkerRush(UnitTypeTable.utt, new BFSPathFinding());
        AI ai1 = new LightRush(utt, new BFSPathFinding());
//        AI ai1 = new RangedRush(UnitTypeTable.utt, new GreedyPathFinding());
//        AI ai1 = new ContinuingNaiveMC(PERIOD, 200, 0.33f, 0.2f, new RandomBiasedAI(), new SimpleEvaluationFunction());

        AI ai2 = new RandomBiasedAI();
//        AI ai2 = new LightRush();
        
        XMLWriter xml = new XMLWriter(new OutputStreamWriter(System.out));
        pgs.toxml(xml);
        xml.flush();

        JFrame w = PhysicalGameStatePanel.newVisualizer(gs,640,640, true);

        long nextTimeToUpdate = System.currentTimeMillis() + PERIOD;
        do{
            if (System.currentTimeMillis()>=nextTimeToUpdate) {
                PlayerAction pa1 = ai1.getAction(0, new PartiallyObservableGameState(gs,0));
                PlayerAction pa2 = ai2.getAction(1, new PartiallyObservableGameState(gs,1));
                gs.issueSafe(pa1);
                gs.issueSafe(pa2);

                // simulate:
                gameover = gs.cycle();
                w.repaint();
                nextTimeToUpdate+=PERIOD;
            } else {
                try {
                    Thread.sleep(1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }while(!gameover && gs.getTime()<MAXCYCLES);
        ai1.gameOver(gs.winner());
        ai2.gameOver(gs.winner());
        
        System.out.println("Game Over");
    }
 
Example 20
Source File: Game.java    From microrts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * run the main loop of the game
 * @param w a window where the game will be displayed
 * @throws Exception
 */
public void start(JFrame w) throws Exception {
    // Reset all players
    ai1.reset();
    ai2.reset();

    // pre-game analysis
    ai1.preGameAnalysis(gs, 0);
    ai2.preGameAnalysis(gs, 0);

    boolean gameover = false;

    while (!gameover && gs.getTime() < maxCycles) {
        long timeToNextUpdate = System.currentTimeMillis() + updateInterval;

        rts.GameState playerOneGameState =
                partiallyObservable ? new PartiallyObservableGameState(gs, 0) : gs;
        rts.GameState playerTwoGameState =
                partiallyObservable ? new PartiallyObservableGameState(gs, 1) : gs;

        rts.PlayerAction pa1 = ai1.getAction(0, playerOneGameState);
        rts.PlayerAction pa2 = ai2.getAction(1, playerTwoGameState);
        gs.issueSafe(pa1);
        gs.issueSafe(pa2);

        // simulate
        gameover = gs.cycle();

        // if not headless mode, wait and repaint the window
        if (w != null) {
            if (!w.isVisible())
                break;

            // only wait if the AIs have not already consumed more time than the predetermined interval
            long waitTime = timeToNextUpdate - System.currentTimeMillis();
            if (waitTime >=0) {
                try {
                    Thread.sleep(waitTime);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            // repaint the window after (or regardless of) wait time
            w.repaint();
        }
    }
    ai1.gameOver(gs.winner());
    ai2.gameOver(gs.winner());
}