java.awt.Container.validate()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(152)

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

Container.validate介绍

[英]Validates this container and all of its subcomponents.

The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.
[中]验证此容器及其所有子组件。
validate方法用于使容器再次布局其子组件。在显示容器后修改(添加到容器中或从容器中删除,或更改布局相关信息)此容器的子组件时,应调用它。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

private static void useProgressBarHelper(Container parent, JComponent add, JComponent remove) {
 GridBagConstraints c = new GridBagConstraints();
 c.fill = GridBagConstraints.BOTH;
 c.weightx = 1.7;
 parent.remove(remove);
 parent.add(add,c);
 parent.validate();
 parent.repaint();
}

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

import javax.swing.*;
import java.awt.*;

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    frame.setSize(600, 400);

    JPanel panel = new JPanel() {
      @Override
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLUE);
        g.fillRect(0, 0, 100, 100);
      }
    };
    frame.add(panel);

    // Graphics g = panel.getGraphics();
    // g.setColor(Color.BLUE);
    // g.fillRect(0, 0, 100, 100);

    frame.validate(); // because you added panel after setVisible was called
    frame.repaint(); // because you added panel after setVisible was called
  }
}

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

JPanel p = new JPanel();
    mediaTypes.createGui(p, show);
    add(p);
    validate();
    MediaTypes mediaTypes = new MediaTypes();
    JPanel p = new JPanel();
    mediaTypes.createGui(p);
    JOptionPane.showMessageDialog(null,p);
panel.add(output, BorderLayout.SOUTH);
d = new Dimension(450,d.height);
tableScroll.setPreferredSize(d);
panel.add( tableScroll, BorderLayout.CENTER );

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

frame.getContentPane().add(button);
  frame.pack();
  frame.setVisible(true);
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
dialog.getContentPane().add(progressBar);
dialog.pack();
dialog.setModal( false );
JLabel label = new JLabel("Task Complete");
dialog.getContentPane().remove(progressBar);
dialog.getContentPane().add(label);
dialog.getContentPane().validate();

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

setDefaultCloseOperation(EXIT_ON_CLOSE);
setUndecorated(isFullScreen);
setResizable(!isFullScreen);
  validate();
} else {
  this.setVisible(true);

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

import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class Test {

  public Test() {
    final JFrame frame = new JFrame("Screen Saver");
    frame.validate();
    frame.setVisible(true);

    KeyAdapter listener = new KeyAdapter() {
      @Override public void keyPressed(KeyEvent e) {
        frame.dispose();
      }
    };

    frame.addKeyListener(listener);
  }

  public static void main(String[] args) {
    new Test();
  }

}

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

public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);
  frame.setSize(600, 400);
  frame.add(panel);
  frame.validate(); // because you added panel after setVisible was called

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

private static final int           TOP               = 0x03;
private static final int           BOTTOM            = 0x04;
private final JPanel               basePanel         = new JPanel();
private final ParentType           parent;
private final Object               lock              = new Object();
  glassPane = new JPanel();
  glassPane.setOpaque(false);
  glassPane.addMouseListener(new MouseAdapter() {
  basePanel.setLayout(new BorderLayout());
  if (useSlideButton) {
    final JPanel statusPanel = new JPanel();
    basePanel.add(statusPanel, BorderLayout.SOUTH);
    statusPanel.add(new JButton("Slide Left") {
      private static final long serialVersionUID = 9204819004142223529L;
    statusPanel.add(new JButton("Slide Right") {
    ((JFrame) parent).getContentPane().setBackground(jPanels.get(0).getBackground());
    parent.remove(basePanel);
    parent.validate();
    parent.validate();
    parent.validate();

代码示例来源:origin: nodebox/nodebox

Dimension d = getSize();
  parent.remove(this);
  parent.add(newPane);
  newPane.setSize(d);
parent.validate();
SwingUtilities.invokeLater(new Runnable() {
  public void run() {

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

Component c = f.getComponents()[0];
f.remove(c);
f.setVisible(false);
add(c);
validate();

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

this.device = device;
setTitle("Display Mode Test");
setDefaultCloseOperation(EXIT_ON_CLOSE);
  validate();
} else {
  setVisible(true);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-xml-xam-ui

void mouseRelease(MouseEvent e){
    if(alreadyDrawn){
      if(SplitterLayout.dragee!=this) return;
      SplitterLayout.dragee = null;
      Point p = wBar.getLocationOnScreen();
      SwingUtilities.convertPointFromScreen(p, getParent());
      wBar.setVisible(false);
      wBar.dispose();
      wBar = null;
      alreadyDrawn = false;
      Rectangle r = getBounds(); // mouse event is relative to this...
      r.x += e.getX();
//            //System.out.println("mouseReleased converted point "+ p);
//            //System.out.println("mouseRelease bounds of this spliltter " + r);
      setLocation(p.x, r.y);
      setCursor(DEF_CURSOR);
      
      // check to see if we need to move other splitters and hide other
      // components that are controlled by the layout
      // First -- find what component this one is
      
      checkOtherComponents();
      mouseInside = false;
      invalidate();
      getParent().validate();
      SplitterLayout.dragee = null;
    }
  }

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

super("Add component on JFrame at runtime");
setLayout(new BorderLayout());
this.panel = new JPanel();
this.panel.setLayout(new FlowLayout());
add(panel, BorderLayout.CENTER);
JButton button = new JButton("CLICK HERE");
add(button, BorderLayout.SOUTH);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setVisible(true);
this.panel.add(new JButton("Button"));
this.panel.revalidate();
validate();

代码示例来源:origin: antlr/antlrworks

private void createErrorPanel() {
  container.removeAll();
  JPanel panel = new JPanel(new BorderLayout());
  panel.add(createErrorPane(), BorderLayout.NORTH);
  panel.add(createVisualizationPane(), BorderLayout.CENTER);
  container.add(panel, BorderLayout.CENTER);
  container.add(createControlPane(), BorderLayout.SOUTH);
  container.validate();
}

代码示例来源:origin: jshiell/checkstyle-idea

private void moveToStep(final Step newStep) {
  remove(panelForCurrentStep());
  currentStep = newStep;
  if (currentStep.isAllowCommit()) {
    commitButton.setText(CheckStyleBundle.message("config.file.okay.text"));
    commitButton.setToolTipText(CheckStyleBundle.message("config.file.okay.text"));
  } else {
    commitButton.setText(CheckStyleBundle.message("config.file.next.text"));
    commitButton.setToolTipText(CheckStyleBundle.message("config.file.next.text"));
  }
  previousButton.setEnabled(currentStep.isAllowPrevious());
  commitButton.setEnabled(currentStep.isAllowNext() || currentStep.isAllowCommit());
  getContentPane().add(panelForCurrentStep(), BorderLayout.CENTER);
  getContentPane().validate();
  getContentPane().repaint();
}

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

((Window) floatingToolBar).setVisible(false);
  UIManager.removePropertyChangeListener(propertyListener);
dockingSource.add(toolBar, constraint.intValue());
dockingSource.invalidate();
Container dockingSourceParent = dockingSource.getParent();
if (dockingSourceParent != null) {
  dockingSourceParent.validate();

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

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel gui = new JPanel(new BorderLayout(5,5));
gui.setBorder( new TitledBorder("BorderLayout(5,5)") );
JPanel plafComponents = new JPanel(
  new FlowLayout(FlowLayout.RIGHT, 3,3));
plafComponents.setBorder(
plafComponents.add(plafChooser);
plafComponents.add(pack);
gui.add(plafComponents, BorderLayout.NORTH);
JPanel dynamicLabels = new JPanel(new BorderLayout(4,4));
dynamicLabels.setBorder(
  new TitledBorder("BorderLayout(4,4)") );
    labels.add( new JLabel("Label " + ++labelCount) );
    frame.validate();
frame.setVisible(true);

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

//<applet code='Apletas' width='600' height='400'></applet>
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

public class Apletas extends JApplet {

  private JTextField inputLine;

  public Apletas()
  {
    inputLine = new JTextField(20);

    JPanel mainGui = new JPanel(new BorderLayout(20,20));
    mainGui.setBorder(new EmptyBorder(80,80,80,80));

    mainGui.add(inputLine, BorderLayout.NORTH);

    mainGui.add(new JScrollPane(new JTextArea(20,10)), BorderLayout.CENTER);
    JTree tree = new JTree();
    tree.expandRow(2);
    mainGui.add(new JScrollPane(tree), BorderLayout.WEST);

    setContentPane(mainGui);
    validate();
  }
}

代码示例来源:origin: nodebox/nodebox

public void close() {
  Container parent = getParent();
  if (!(parent instanceof JSplitPane)) return;
  JSplitPane split = (JSplitPane) parent;
  Component firstComponent = split.getTopComponent();
  Component secondComponent = split.getBottomComponent();
  Component remainingComponent = firstComponent == this ? secondComponent : firstComponent;
  split.setTopComponent(null);
  split.setBottomComponent(null);
  Container grandParent = parent.getParent();
  if (grandParent instanceof JSplitPane) {
    JSplitPane grandSplit = (JSplitPane) grandParent;
    // Remove the split pane.
    if (split == grandSplit.getTopComponent()) {
      grandSplit.setTopComponent(remainingComponent);
    } else {
      grandSplit.setBottomComponent(remainingComponent);
    }
  } else {
    grandParent.remove(parent);
    grandParent.add(remainingComponent);
  }
  grandParent.validate();
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

public void windowClosing(WindowEvent w)
{
  if (toolBar.isFloatable() == true)
  {
    if (dragWindow != null)
      dragWindow.setVisible(false);
    floating= false;
    if (floatingToolBar == null)
      floatingToolBar= createFloatingWindow(toolBar);
    if (floatingToolBar instanceof Window)
       ((Window) floatingToolBar).setVisible(false);
    floatingToolBar.getContentPane().remove(toolBar);
    String constraint= constraintBeforeFloating;
    int orientation= mapConstraintToOrientation(constraint);
    setOrientation(orientation);
    if (dockingSource == null)
      dockingSource= toolBar.getParent();
    if (propertyListener != null)
      UIManager.removePropertyChangeListener(propertyListener);
    dockingSource.add(constraint, toolBar);
    dockingSource.invalidate();
    Container dockingSourceParent= dockingSource.getParent();
    if (dockingSourceParent != null)
      dockingSourceParent.validate();
    dockingSource.repaint();
    setFloating(false, null);
  }
}

相关文章

微信公众号

最新文章

更多

Container类方法