Java Code Examples for javax.swing.JPanel.validate()

The following are Jave code examples for showing how to use validate() of the javax.swing.JPanel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AgentWorkbench   File: DynForm.java   View Source Code Vote up 6 votes
@Override
protected void removeMultiple(DefaultMutableTreeNode node){
	
	// --- Remind all needed informations -------------------------------------------
	DefaultMutableTreeNode previousNode = node.getPreviousNode();
	DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
	
	DynType dt = (DynType) node.getUserObject();
	JPanel deletePanel = dt.getPanel();
	JPanel parentPanel = (JPanel) deletePanel.getParent();
	
	int movement = (deletePanel.getHeight() + 2) * (-1);
	
	// --- Remove node from the parent node and panel -------------------------------
	DynType dyntype = (DynType) node.getUserObject();
	node.setUserObject(null);
	parentNode.remove(node);
	this.getTreeNodesByDynType().remove(dyntype);
	
	// --- remove the panel from the parent -----------------------------------------
	parentPanel.remove(deletePanel);
	parentPanel.validate();
	this.setPanelBounds(parentPanel);
	
	// --- Now move the rest of the elements on the form ----------------------------
	this.moveAfterAddOrRemove(movement, previousNode);

	// --- refresh the GUI ----------------------------------------------------------
	this.adjustPreferredSize();
	
}
 
Example 2
Project: jaer   File: CochleaAMS1cRollingCochleagramADCDisplayMethod.java   View Source Code Vote up 6 votes
private void checkAndAddToViewer() {
	if(addedToViewer) {
		return;
	}
	AEChip chip = (AEChip) getChipCanvas().getChip();
	if(chip==null) {
		return;
	}
	AEViewer viewer = chip.getAeViewer(); // must do lazy install here because viewer hasn't been registered with this chip at this point
	if(viewer==null) {
		return;
	}
	JPanel imagePanel = viewer.getImagePanel();
	if(imagePanel==null) {
		return;
	}
	imagePanel.add(activityPan, BorderLayout.SOUTH);
	imagePanel.validate();
	addedToViewer=true;
}
 
Example 3
Project: ramus   File: RubyConsole.java   View Source Code Vote up 5 votes
public JComponent createComponent() {
    JPanel panel = new JPanel();
    JPanel console = new JPanel();
    panel.setLayout(new BorderLayout());

    final JEditorPane text = new JTextPane();

    text.setMargin(new Insets(8, 8, 8, 8));
    text.setCaretColor(new Color(0xa4, 0x00, 0x00));
    text.setBackground(new Color(0xf2, 0xf2, 0xf2));
    text.setForeground(new Color(0xa4, 0x00, 0x00));
    Font font = findFont("Monospaced", Font.PLAIN, 14, new String[]{
            "Monaco", "Andale Mono"});

    text.setFont(font);
    JScrollPane pane = new JScrollPane();
    pane.setViewportView(text);
    pane.setBorder(BorderFactory.createLineBorder(Color.darkGray));
    panel.add(pane, BorderLayout.CENTER);
    console.validate();

    final TextAreaReadline tar = new TextAreaReadline(text,
            getString("Wellcom") + " \n\n");

    RubyInstanceConfig config = new RubyInstanceConfig() {
        {
            //setInput(tar.getInputStream());
            //setOutput(new PrintStream(tar.getOutputStream()));
            //setError(new PrintStream(tar.getOutputStream()));
            setObjectSpaceEnabled(false);
        }
    };
    Ruby runtime = Ruby.newInstance(config);
    tar.hookIntoRuntimeWithStreams(runtime);

    run(runtime);
    return panel;
}
 
Example 4
Project: freecol   File: ChooseFoundingFatherDialog.java   View Source Code Vote up 5 votes
/**
 * The constructor that will add the items to this panel.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param possibleFoundingFathers The {@code FoundingFather}s
 *     which can be selected. The length of the array is the same
 *     as the number of {@code FoundingFather} categories and the
 *     values identifies a {@code FoundingFather} to be picked in
 *     each of those categories.
 */
public ChooseFoundingFatherDialog(FreeColClient freeColClient, JFrame frame,
        List<FoundingFather> possibleFoundingFathers) {
    super(freeColClient, frame);

    this.possibleFathers = possibleFoundingFathers;
    this.tb = new JTabbedPane(JTabbedPane.TOP);

    JButton helpButton = new JButton(freeColClient.getActionManager()
        .getFreeColAction("colopediaAction.fathers"));
    helpButton.setText(Messages.message("help"));

    FatherDetailPanel details = new FatherDetailPanel(freeColClient,
        new ColopediaPanel(freeColClient));
    for (FoundingFather father : possibleFoundingFathers) {
        JPanel jp = new MigPanel();
        details.buildDetail(father, jp);
        jp.validate();
        tb.addTab(Messages.message(father.getTypeKey()), jp);
    }
    tb.setSelectedIndex(0);

    MigPanel panel = new MigPanel(new MigLayout("wrap 1", "align center"));
    panel.add(Utility.localizedHeader("chooseFoundingFatherDialog.title", false));
    panel.add(helpButton, "tag help");
    panel.add(tb, "width 100%");
    panel.setPreferredSize(panel.getPreferredSize());

    List<ChoiceItem<FoundingFather>> c = choices();
    c.add(new ChoiceItem<>(Messages.message("ok"), (FoundingFather)null)
        .okOption().defaultOption());
    initializeDialog(frame, DialogType.QUESTION, false, panel, null, c);
}
 
Example 5
Project: FreeCol   File: ChooseFoundingFatherDialog.java   View Source Code Vote up 5 votes
/**
 * The constructor that will add the items to this panel.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param possibleFoundingFathers The {@code FoundingFather}s
 *     which can be selected. The length of the array is the same
 *     as the number of {@code FoundingFather} categories and the
 *     values identifies a {@code FoundingFather} to be picked in
 *     each of those categories.
 */
public ChooseFoundingFatherDialog(FreeColClient freeColClient, JFrame frame,
        List<FoundingFather> possibleFoundingFathers) {
    super(freeColClient, frame);

    this.possibleFathers = possibleFoundingFathers;
    this.tb = new JTabbedPane(JTabbedPane.TOP);

    JButton helpButton = new JButton(freeColClient.getActionManager()
        .getFreeColAction("colopediaAction.fathers"));
    helpButton.setText(Messages.message("help"));

    FatherDetailPanel details = new FatherDetailPanel(freeColClient,
        new ColopediaPanel(freeColClient));
    for (FoundingFather father : possibleFoundingFathers) {
        JPanel jp = new MigPanel();
        details.buildDetail(father, jp);
        jp.validate();
        tb.addTab(Messages.message(father.getTypeKey()), jp);
    }
    tb.setSelectedIndex(0);

    MigPanel panel = new MigPanel(new MigLayout("wrap 1", "align center"));
    panel.add(Utility.localizedHeader("chooseFoundingFatherDialog.title", false));
    panel.add(helpButton, "tag help");
    panel.add(tb, "width 100%");
    panel.setPreferredSize(panel.getPreferredSize());

    List<ChoiceItem<FoundingFather>> c = choices();
    c.add(new ChoiceItem<>(Messages.message("ok"), (FoundingFather)null)
        .okOption().defaultOption());
    initializeDialog(frame, DialogType.QUESTION, false, panel, null, c);
}
 
Example 6
Project: jOthelloT   File: Results.java   View Source Code Vote up 5 votes
public void saveFinal(JPanel panel, String jogoNro) {
    try {
        panel.validate();
        panel.repaint();
        panel.validate();
        panel.repaint();
        Container c = panel;
        BufferedImage im = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
        c.paint(im.getGraphics());
        ImageIO.write(im, "PNG", new File(PATH + File.separator + "jogo" + jogoNro + ".png"));
    } catch (IOException ex) {
        Logger.getLogger(OthelloTournament.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 7
Project: AgentWorkbench   File: DynForm.java   View Source Code Vote up 4 votes
@Override
protected DefaultMutableTreeNode addSingleMultipleNode(DefaultMutableTreeNode node, boolean isInnerClass){
	
	// --- Get all needed information about the node, which has to be copied --------
	DynType dt = (DynType) node.getUserObject();
	String clazz = dt.getClassName();
	OntologySingleClassSlotDescription oscsd = dt.getOntologySingleClassSlotDescription();
	
	JPanel oldPanel = dt.getPanel();
	JPanel parentPanel = (JPanel) oldPanel.getParent();

	// --- Get parent node ----------------------------------------------------------
	DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); 
	int depth2WorkOn = parentNode.getLevel()-1;
	
	// --- Create the panel/node as needed as a copy of the current node ------------
	JPanel blindPanel = new JPanel();
	blindPanel.setLayout(null);
	DefaultMutableTreeNode newNode = null;
	
	if (isInnerClass==true) {
		newNode = this.createInnerElements(oscsd, clazz, depth2WorkOn+1, blindPanel, parentNode, true);
		if (oldPanel.isVisible()==false) {
			// --- Case special class: set invisible and small ------------ 
			this.setJPanelInvisibleAndSmall(newNode);
		}
		
	} else {
		newNode = this.createOuterElements(oscsd, depth2WorkOn, blindPanel, parentNode, true);
	}
	
	// --- Place the node at the right position in the tree -------------------------
	newNode.removeFromParent();
	int nodeIndexPos = parentNode.getIndex(node)+1;
	objectTree.insertNodeInto(newNode, parentNode, nodeIndexPos);
	
	// --- Set the size of the new Panel --------------------------------------------
	DynType dtNew = (DynType) newNode.getUserObject();
	JPanel newPanel = dtNew.getPanel();
	
	// --- Layout the new panel -----------------------------------------------------
	if (oldPanel.isVisible()==true) {
		// ----------------------------------------------------------------
		// --- The normal case for visible classes ------------------------
		// ----------------------------------------------------------------			
		this.setPanelBounds(newPanel);
		newPanel.setPreferredSize(newPanel.getSize());

		// --- Now place the new sub panel on the right super panel -------
		int movement = oldPanel.getHeight() + 2;
		int xPos = oldPanel.getX();
		int yPos = oldPanel.getY() + movement;
		newPanel.setBounds(xPos, yPos, newPanel.getWidth(), newPanel.getHeight());
		
		// --- Add to parent panel ----------------------------------------
		parentPanel.add(newPanel);
		parentPanel.validate();
		this.setPanelBounds(parentPanel);
		
		// --- Now move the rest of the elements on the form ----------------------------
		this.moveAfterAddOrRemove(movement, newNode);
		
	} else {
		// ----------------------------------------------------------------
		// --- The case for special classes, that have to be invisible ----
		// ----------------------------------------------------------------
		newPanel.setVisible(false);
		newPanel.setBounds(oldPanel.getBounds());
		
	}
	
	// --- refresh the GUI ----------------------------------------------------------
	this.adjustPreferredSize();
	
	return newNode;
}
 
Example 8
Project: AgentWorkbench   File: DynForm.java   View Source Code Vote up 4 votes
/**
 * Move all elements which are available after the node given by the parameter node.
 *
 * @param movement the movement
 * @param node the node
 */
private void moveAfterAddOrRemove(int movement, DefaultMutableTreeNode node) {
	
	if (node==this.getRootNode()) return;
	
	DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
	JPanel parentPanel = null;
	if (parentNode.getUserObject() instanceof DynType) {
		DynType dynType = (DynType) parentNode.getUserObject();
		parentPanel = dynType.getPanel();
	}
	
	int numOfChilds = parentNode.getChildCount();
	int indexOfNextNode = parentNode.getIndex(node) + 1;
	
	for (int i = indexOfNextNode; i < numOfChilds; i++) {
		
		DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) parentNode.getChildAt(i);

		DynType dt = (DynType) currNode.getUserObject();
		JPanel movePanel = dt.getPanel();
		movePanel.setBounds(movePanel.getX(), movePanel.getY()+movement, movePanel.getWidth(), movePanel.getHeight());
		
		JComponent parentComp = (JComponent) movePanel.getParent();
		parentComp.validate();
		if (parentComp instanceof JPanel) {
			this.setPanelBounds((JPanel) parentComp);	
		}
		
	}

	// --- Configure size of parent panel -----------------------
	if (parentPanel!=null) {
		parentPanel.validate();
		this.setPanelBounds(parentPanel);
	}
	
	// --- do the same at the parent node -----------------------
	this.moveAfterAddOrRemove(movement, parentNode);
	
}