javax.swing.JFrame.revalidate()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(342)

本文整理了Java中javax.swing.JFrame.revalidate()方法的一些代码示例,展示了JFrame.revalidate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.revalidate()方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名:revalidate

JFrame.revalidate介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

JButton myButton = new JButton("Open new window");
JFrame newFrame = new JFrame("New Window");
 myButton.addActionListener(new ActionListener() {
 public void actionPerformed(ActionEvent e) {
 newFrame.pack();
 newFrame.setVisible(true);
 newFrame.revalidate();
 }
 });

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.setSize(300,300);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(new JLabel("Label"));
  frame.revalidate();
  frame.repaint();
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  final JFrame frame = new JFrame();
  frame.setTitle("Title");
  frame.setSize(500, 350);
  frame.setResizable(false);
  frame.setLocationRelativeTo(null);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  JButton a = new JButton("button A");
  frame.setContentPane(a);

  frame.setVisible(true); // calling setVisible after content pane has been set to refresh a frame

  a.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      JComponent b = new JLabel("label B");
      frame.setContentPane(b);
      frame.revalidate();
    }
  });
}

代码示例来源:origin: stackoverflow.com

public JFrame frame = new JFrame();
public JPanel pan = new JPanel();

public void replace() {
 frame.remove(pan);
 pan = new JPanel();
 GridLayout grid = new GridLayout(8,8);
 pan.setLayout(grid);
 pan.setVisible(true);
 frame.add(pan);
 frame.invalidate();
 frame.revalidate();
 frame.repaint();
 frame.pack();
 frame.setVisible(true);
}

代码示例来源:origin: stackoverflow.com

public Game() {
  model = new Model();
  model.add(new Tile(Tile.randomLetter(), Color.WHITE));
  model.add(new Tile(Tile.randomLetter(), Color.RED));
  model.add(new Tile(Tile.randomLetter(), Color.GREEN));
  model.add(new Tile(Tile.randomLetter(), Color.YELLOW));

  JFrame frame = new JFrame();
  frame.getContentPane().setLayout(new GridLayout(4, 1));
  frame.setSize(500, 800);
  frame.setVisible(true);

  for (Tile tile : model.getTiles()) {
    frame.add(tile);
  }

  model.addModelListener(new ModelListener() {
    @Override
    public void tileWasRemoved(Tile tile) {
      frame.remove(tile);
      frame.revalidate();
      frame.repaint();
    }
  });
  frame.getContentPane().addKeyListener(this);
  frame.getContentPane().setFocusable(true);
  frame.getContentPane().requestFocusInWindow();
}

代码示例来源:origin: stackoverflow.com

jf.add(jl[i]);
 jf.revalidate();
jf.setVisible(true);

代码示例来源:origin: stackoverflow.com

JFrame test = new TestMain();
test.revalidate();

代码示例来源:origin: stackoverflow.com

public class Test {

  public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(null);

    JButton button = new JButton("Test");                       
    button.setBounds(20, 30, 100, 40);
    button.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent e) {
        JPanel panel = new JPanel();
        panel.setBackground(Color.red);
        panel.setBounds(215, 2, 480, 480);
        frame.add(panel);
        frame.revalidate(); // Repaint here!! Removing these calls
        frame.repaint(); // demonstrates the problem you are having.

      }
    }); 

    frame.add(button);
    frame.setSize(695, 482);
    frame.setVisible(true);              

  }
}

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
final JPanel origPanel = new JPanel();
frame.add(origPanel, BorderLayout.CENTER);

MouseListener ml = new MouseAdapter() {
 public void mouseClicked(MouseEvent evt) {
  // Mouse clicked on panel so remove existing panel and add a new one.
  frame.remove(origPanel);
  frame.add(createNewPanel(), BorderLayout.CENTER);

  // Revalidate frame to cause it to layout the new panel correctly.
  frame.revalidate();

  // Stop listening to origPanel (prevent dangling reference).
  origPanel.removeMouseListener(this);
 }
}

origPanel.addMouseListener(ml);

代码示例来源:origin: stackoverflow.com

frame.revalidate();

代码示例来源:origin: stackoverflow.com

private void addImageOuter(final String image){
   final JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
   SwingUtilities.invokeLater(new Runnable() {
     @Override
     public void run() {
       imagePanel.addImageInner(image);
       frame.revalidate();
       final JScrollBar vScroll = imageScrollPane.getVerticalScrollBar();
       vScroll.setValue(vScroll.getMaximum());
     }
   });
 }

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  final JFrame frame = new JFrame("Test");
  frame.setLayout(new BorderLayout());
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  final Canvas canvas1 = new Canvas();
  final Canvas canvas2 = new Canvas();
  canvas1.setBackground(Color.RED);
  canvas2.setBackground(Color.BLUE);
  canvas1.addMouseListener(new MouseAdapter() {
    @Override public void mouseClicked(MouseEvent e) {
      frame.remove(canvas1);
      frame.add(canvas2, BorderLayout.CENTER);
      System.out.println("Canvas switched to Canvas2");
      frame.revalidate();
    }
  });

  SwingUtilities.invokeLater(new Runnable() {
    @Override public void run() {
      frame.add(canvas1);
      frame.setSize(640, 480);
      frame.setVisible(true);
    }
  });
}

代码示例来源:origin: stackoverflow.com

frame.revalidate();                 // CRITICAL MISSING LINES

代码示例来源:origin: stackoverflow.com

public class FTW {
  public static void main(String[] args) throws IOException {

    JFrame myFrame = new JFrame("myJfTitle");
    myFrame.setSize(300,100);
    myFrame.setLayout(new BorderLayout());
    JPanel myPanel = new JPanel();
    JButton myButton = new JButton("Click me");
    JProgressBar myBar = new JProgressBar();
    myBar.setPreferredSize(new Dimension(myFrame.getWidth(),myFrame.getHeight())); //sets the size for the first time
    myFrame.addComponentListener(new ComponentAdapter()  //sets the size everytime the frame is resized
    {  
        public void componentResized(ComponentEvent evt) {
          Component c = (Component)evt.getSource();
          myBar.setPreferredSize(new Dimension(myFrame.getWidth(),myFrame.getHeight()));
        }
    });
    JPanel glass = (JPanel) myFrame.getGlassPane();
    glass.setVisible(true);
    myBar.setValue(50);
    glass.add(myButton, BorderLayout.CENTER);
    myPanel.add(myBar);
    myFrame.add(myPanel);
    myFrame.revalidate();
    myFrame.repaint();
    myFrame.setVisible(true);
}
}

代码示例来源:origin: stackoverflow.com

mainFrame.revalidate();
mainFrame.repaint();

代码示例来源:origin: stackoverflow.com

public void actionPerformed(ActionEvent e) {
  frame.setContentPane(panel2);
  frame.revalidate();
  panel2.getTextField().requestFocusInWindow();
public void actionPerformed(ActionEvent e) {
  frame.setContentPane(panel1);
  frame.revalidate();
  panel1.getTextField().requestFocusInWindow();

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

@Override
  public void run()
  {
    
    Lancador.getInstance().getJFrame().setUndecorated(true);
    outSidePanel = new OutsidePanel();
    Lancador.getInstance().getJFrame().add(outSidePanel);
    telaPrincipal = outSidePanel.getTelaPrincipal();
    telaPrincipal.setArquivosIniciais(arquivosIniciais);
    Lancador.getInstance().getJFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    Lancador.getInstance().getJFrame().pack();
    Lancador.getInstance().getJFrame().setLocationRelativeTo(null);
    Lancador.getInstance().getJFrame().setVisible(true);
    Lancador.getInstance().setOlderSize(new Dimension(800, 600));
    Lancador.getInstance().maximize(true);
    
    Lancador.getInstance().getJFrame().revalidate();
    portugolCarregado = true;
  }
});

代码示例来源:origin: stackoverflow.com

frame.add(game);                                
game.setVisible(true);                      
frame.revalidate();
animationTimer.start();

代码示例来源:origin: GrammarViz2/grammarviz2_src

frame.revalidate();
frame.repaint();

相关文章

JFrame类方法