Java Code Examples for java.awt.event.ComponentEvent

The following are top voted examples for showing how to use java.awt.event.ComponentEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: EditorCaret.java   Source Code and License 6 votes vote down vote up
/**
 * May be called for either component or horizontal scrollbar.
 */
public @Override void componentResized(ComponentEvent e) {
    Component c = e.getComponent();
    if (c == component) { // called for component
        // In case the caretBounds are still null
        // (component not connected to hierarchy yet or it has zero size
        // so the modelToView() returned null) re-attempt to compute the bounds.
        CaretItem caret = getLastCaretItem();
        if (caret.getCaretBounds() == null) {
            dispatchUpdate(false);
            resetBlink();
            if (caret.getCaretBounds() != null) { // detach the listener - no longer necessary
                c.removeComponentListener(this);
            }
        }
    }
}
 
Example 2
Project: QN-ACTR-Release   File: DistributionsEditor.java   Source Code and License 6 votes vote down vote up
@Override
protected void updateValues(ComponentEvent e) {
	//			Get the textfield
	JTextField sourcefield = (JTextField) e.getSource();
	try {
		// Get the probability entered in the textfield
		Double probability = new Double(Double.parseDouble(sourcefield.getText()));
		//Probability has to be smaller or equal than 1 (otherwise don't update value)
		if (probability.doubleValue() <= 1.0) {
			//If the probability was entered into the probability field of interval B
			//then the probability parameter in the distribution has to be set to 1-enteredProbability
			if (sourcefield.getName().equals(PROBABILITY_INTERVAL_B)) {
				probability = new Double(1 - probability.doubleValue());

			}
			//set the parameter
			current.getParameter(0).setValue(probability);
		}
	} catch (NumberFormatException ex) {
		//If user enters a value that is not a number -> reset value back to the value before
	}

	refreshValues();

}
 
Example 3
Project: defense-solutions-proofs-of-concept   File: ComponentShowingButton.java   Source Code and License 6 votes vote down vote up
/**
 * Sets the component to be shown.
 * @param component the component to be shown.
 * @param parent the container to which the shown component should be added.
 *               This parameter can be null if you add the component yourself.
 */
public void setComponent(Component component) {
    this.component = component;
    if (null != component) {
        component.addComponentListener(new ComponentAdapter() {

            @Override
            public void componentHidden(ComponentEvent e) {
                if (null != unselectButton && isSelected()) {
                    unselectButton.setSelected(true);
                }
            }
            
        });
    }
}
 
Example 4
Project: openjdk-jdk10   File: SetShape.java   Source Code and License 6 votes vote down vote up
@Override
public void initGUI() {
    if (windowClass.equals(Frame.class)) {
        window = new Frame();
        ((Frame) window).setUndecorated(true);
    } else  if (windowClass.equals(Dialog.class)) {
        window = new Dialog(background);
        ((Dialog) window).setUndecorated(true);
    } else {
        window = new Window(background);
    }
    window.setBackground(FG_COLOR);
    window.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            window.setShape(shape);
        }
    });
    window.setSize(200, 200);
    window.setLocation(2*dl, 2*dl);
    window.setVisible(true);

    System.out.println("Checking " + window.getClass().getName() + "...");
}
 
Example 5
Project: incubator-netbeans   File: AutoHideStatusText.java   Source Code and License 6 votes vote down vote up
private AutoHideStatusText( JFrame frame, JPanel statusContainer  ) {
    this.statusContainer = statusContainer;
    Border outerBorder = UIManager.getBorder( "Nb.ScrollPane.border" ); //NOI18N
    if( null == outerBorder ) {
        outerBorder = BorderFactory.createEtchedBorder();
    }
    panel.setBorder( BorderFactory.createCompoundBorder( outerBorder, 
            BorderFactory.createEmptyBorder(3,3,3,3) ) );
    lblStatus.setName("AutoHideStatusTextLabel"); //NOI18N
    panel.add( lblStatus, BorderLayout.CENTER );
    frame.getLayeredPane().add( panel, Integer.valueOf( 101 ) );
    StatusDisplayer.getDefault().addChangeListener( this );

    frame.addComponentListener( new ComponentAdapter() {
        @Override
        public void componentResized( ComponentEvent e ) {
            run();
        }
    });
}
 
Example 6
Project: openjdk-jdk10   File: FontPanel.java   Source Code and License 6 votes vote down vote up
public FontPanel( Font2DTest demo, JFrame f ) {
    f2dt = demo;
    parent = f;

    verticalBar = new JScrollBar ( JScrollBar.VERTICAL );
    fc = new FontCanvas();

    this.setLayout( new BorderLayout() );
    this.add( "Center", fc );
    this.add( "East", verticalBar );

    verticalBar.addAdjustmentListener( this );
    this.addComponentListener( new ComponentAdapter() {
        public void componentResized( ComponentEvent e ) {
            updateFontMetrics = true;
        }
    });

    /// Initialize font and its infos
    testFont = new Font(fontName, fontStyle, (int)fontSize);
    if ((float)((int)fontSize) != fontSize) {
        testFont = testFont.deriveFont(fontSize);
    }
    updateFontInfo();
}
 
Example 7
Project: BachSys   File: TelaDadosMusica.java   Source Code and License 6 votes vote down vote up
private void adicionarBotaoEditar() {
    Tela t = this;
    btnEditar = new JButton("Editar");
    adicionarComponente(btnEditar, GridBagConstraints.EAST, 
                GridBagConstraints.NONE, 0, 0, 2, 1);
    btnEditar.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            TelaEditarMusica tem = new TelaEditarMusica(musica.getNome(), musica, t);
            tem.setVisible(true);
            tem.addComponentListener(new ComponentAdapter() {
                @Override
                public void componentHidden(ComponentEvent e) {
                    musica = tem.getMusica();
                    editou = true;
                    adicionarValores();
                }
            });
        }
    });
}
 
Example 8
Project: incubator-netbeans   File: UIUtils.java   Source Code and License 6 votes vote down vote up
public static void ensureMinimumSize(Component comp) {
    comp = getParentWindow(comp);

    if (comp != null) {
        final Component top = comp;
        top.addComponentListener(new ComponentAdapter() {
                public void componentResized(ComponentEvent e) {
                    Dimension d = top.getSize();
                    Dimension min = top.getMinimumSize();

                    if ((d.width < min.width) || (d.height < min.height)) {
                        top.setSize(Math.max(d.width, min.width), Math.max(d.height, min.height));
                    }
                }
            });
    }
}
 
Example 9
Project: OpenJSharp   File: FontPanel.java   Source Code and License 6 votes vote down vote up
public FontPanel( Font2DTest demo, JFrame f ) {
    f2dt = demo;
    parent = f;

    verticalBar = new JScrollBar ( JScrollBar.VERTICAL );
    fc = new FontCanvas();

    this.setLayout( new BorderLayout() );
    this.add( "Center", fc );
    this.add( "East", verticalBar );

    verticalBar.addAdjustmentListener( this );
    this.addComponentListener( new ComponentAdapter() {
        public void componentResized( ComponentEvent e ) {
            updateBackBuffer = true;
            updateFontMetrics = true;
        }
    });

    /// Initialize font and its infos
    testFont = new Font(fontName, fontStyle, (int)fontSize);
    if ((float)((int)fontSize) != fontSize) {
        testFont = testFont.deriveFont(fontSize);
    }
    updateFontInfo();
}
 
Example 10
Project: jmt   File: DistributionsEditor.java   Source Code and License 5 votes vote down vote up
@Override
protected void updateValues(ComponentEvent e) {
	// Finds parameter number
	JTextField sourcefield = (JTextField) e.getSource();
	int num = Integer.parseInt(sourcefield.getName());
	current.getParameter(num).setValue(sourcefield.getText());
	current.updateCM();
	refreshValues();
}
 
Example 11
Project: openjdk-jdk10   File: DefaultWindowDriver.java   Source Code and License 5 votes vote down vote up
@Override
public void resize(ComponentOperator oper, int width, int height) {
    checkSupported(oper);
    oper.setSize(width, height);
    eDriver.dispatchEvent(oper.getSource(),
            new ComponentEvent(oper.getSource(),
                    ComponentEvent.COMPONENT_RESIZED));
}
 
Example 12
Project: intellij-bpmn-editor   File: BPMNEditorDiagramTab.java   Source Code and License 5 votes vote down vote up
private void installResizeHandler() {
    addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            fileTab.getGraphComponent().zoomAndCenter();
        }
    });
}
 
Example 13
Project: OpenJSharp   File: Ruler.java   Source Code and License 5 votes vote down vote up
/**
 * Applies the shape to window. It is recommended to apply shape in
 * componentResized() method
 */
@Override
public void componentResized(ComponentEvent e) {

    // We do apply shape only if PERPIXEL_TRANSPARENT is supported
    if (transparencySupported) {
        setShape(buildShape());
    }
}
 
Example 14
Project: TrabalhoFinalEDA2   File: mxGraphComponent.java   Source Code and License 5 votes vote down vote up
/**
 * Applies the zoom policy if the size of the component changes.
 */
protected void installResizeHandler()
{
	addComponentListener(new ComponentAdapter()
	{
		public void componentResized(ComponentEvent e)
		{
			zoomAndCenter();
		}
	});
}
 
Example 15
Project: Manns-Game-of-Life-Updated-Version   File: MGoL_Backend.java   Source Code and License 5 votes vote down vote up
@Override
public void componentResized(ComponentEvent e) 
{
	/*
	 * This method is responsible for the Array Board always being the dimensions of the User Interface.
	 * This is necessary when the user changes the size of the Cells within the Array. 
	 * This inadvertently makes the array smaller and thus, the board ensure the array will stay the same size while adding more cells to accomodate.
	 * This calls the Update Universe Method.
	 */
	// Setup the game board size with proper boundaries
	GameOfLifeDimensions = new Dimension(getWidth()/cellSize-2, getHeight()/cellSize-2);
	updateUniverseSize();
}
 
Example 16
Project: etomica   File: DeviceTrioControllerButton.java   Source Code and License 5 votes vote down vote up
public void componentResized(ComponentEvent e){
    if(firstResized) { width = jp.getParent().getWidth();firstResized =false;}
    if((double)jp.getParent().getWidth()<width){
        jp.setLayout(new java.awt.GridLayout(3,1));
        jp.updateUI();
    } else { 
        jp.setLayout(new java.awt.GridLayout(1,3)); 
        jp.updateUI();
    }
}
 
Example 17
Project: Tarski   File: SimpleGUI.java   Source Code and License 5 votes vote down vote up
/** Called when this window is moved. */
public void componentMoved(ComponentEvent e) {
    AnalyzerWidth.set(frame.getWidth());
    AnalyzerHeight.set(frame.getHeight());
    AnalyzerX.set(frame.getX());
    AnalyzerY.set(frame.getY());
}
 
Example 18
Project: smile_1.5.0_java7   File: PlotCanvas.java   Source Code and License 5 votes vote down vote up
@Override
public void componentResized(ComponentEvent e) {
    if (graphics != null) {
        base.initBaseCoord();
        graphics.projection.reset();
        baseGrid.setBase(base);
    }

    repaint();
}
 
Example 19
Project: batmapper   File: MapperPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void componentResized( ComponentEvent e ) {

    if (visibleDescs) {
        vv.setBounds( 7, BORDERLINE, this.getWidth() - ( DESC_WIDTH + 21 ), this.getHeight() - ( BORDERLINE + 7 ) );
        descPanel.setBounds( this.getWidth() - ( 7 + DESC_WIDTH ), BORDERLINE, DESC_WIDTH, SHORT_DESC_HEIGHT + LONG_DESC_HEIGHT + EXITS_HEIGHT + BUTTON_HEIGHT + 4 * 7 );
        scrollableNotes.setBounds( this.getWidth() - ( 7 + DESC_WIDTH ), BORDERLINE + descPanel.getHeight() + 7, DESC_WIDTH, this.getHeight() - ( descPanel.getHeight() + 14 + BORDERLINE ) );

    } else {
        vv.setBounds( 7, BORDERLINE, this.getWidth() - ( 2 * 7 ), this.getHeight() - ( BORDERLINE + 7 ) );
        descPanel.setBounds( 0, 0, 0, 0 );
        scrollableNotes.setBounds( 0, 0, 0, 0 );
    }

}
 
Example 20
Project: openjdk-jdk10   File: XWindowPeer.java   Source Code and License 5 votes vote down vote up
public void setBounds(int x, int y, int width, int height, int op) {
    XToolkit.awtLock();
    try {
        Rectangle oldBounds = getBounds();

        super.setBounds(x, y, width, height, op);

        Rectangle bounds = getBounds();

        XSizeHints hints = getHints();
        setSizeHints(hints.get_flags() | XUtilConstants.PPosition | XUtilConstants.PSize,
                         bounds.x, bounds.y, bounds.width, bounds.height);
        XWM.setMotifDecor(this, false, 0, 0);

        boolean isResized = !bounds.getSize().equals(oldBounds.getSize());
        boolean isMoved = !bounds.getLocation().equals(oldBounds.getLocation());
        if (isMoved || isResized) {
            repositionSecurityWarning();
        }
        if (isResized) {
            postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_RESIZED));
        }
        if (isMoved) {
            postEventToEventQueue(new ComponentEvent(getEventSource(), ComponentEvent.COMPONENT_MOVED));
        }
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 21
Project: incubator-netbeans   File: AbstractMenuFactory.java   Source Code and License 5 votes vote down vote up
public void componentShown(ComponentEvent e) {
    JMenu menu = (JMenu) e.getComponent();
    String containerCtx = getContainerContext(menu);
    System.err.println("ComponentShown: Menu" + containerCtx + " - " + menu);
    populateMenu(containerCtx, menu);
    getEngine().notifyMenuShown (containerCtx, menu);
}
 
Example 22
Project: Tarski   File: BasicGraphEditor.java   Source Code and License 5 votes vote down vote up
/**
 * 
 */
public EditorPalette insertPalette(String title)
{
	final EditorPalette palette = new EditorPalette();
	final JScrollPane scrollPane = new JScrollPane(palette);
	scrollPane
			.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
	scrollPane
			.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
	libraryPane.add(title, scrollPane);

	// Updates the widths of the palettes if the container size changes
	libraryPane.addComponentListener(new ComponentAdapter()
	{
		/**
		 * 
		 */
		public void componentResized(ComponentEvent e)
		{
			int w = scrollPane.getWidth()
					- scrollPane.getVerticalScrollBar().getWidth();
			palette.setPreferredWidth(w);
		}

	});

	return palette;
}
 
Example 23
Project: incubator-netbeans   File: CustomizerSources.java   Source Code and License 5 votes vote down vote up
public void componentResized(ComponentEvent evt){
    double pw = table.getParent().getParent().getSize().getWidth();
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setWidth( ((int)pw/2) - 1 );
    column.setPreferredWidth( ((int)pw/2) - 1 );
    column = table.getColumnModel().getColumn(1);
    column.setWidth( ((int)pw/2) - 1 );
    column.setPreferredWidth( ((int)pw/2) - 1 );
}
 
Example 24
Project: Java-Swing-Helper   File: SwingWindow.java   Source Code and License 5 votes vote down vote up
/**
 * Load a new scene into the frame.</br>
 * This will clear out the old scene.
 * 
 * @param scene
 */
public void loadScene(Scene scene) {
	if (currentScene != null)
		currentScene.unloadScene();
	currentScene = scene;

	frame.getContentPane().removeAll();
	originalComps.clear();

	scene.loadScene(frame.getContentPane());

	addComponentToList(frame.getContentPane());
	// Used to avoid an infinite loop.
	originalComps.remove(System.identityHashCode(frame.getContentPane()));

	frame.setTitle(title + " - " + scene.getTitle());
	frame.getContentPane().repaint();

	frame.getContentPane().addComponentListener(new ComponentAdapter() {
		@Override
		public void componentResized(ComponentEvent e) {
			pack();
		}
	});

	pack();
}
 
Example 25
Project: Equella   File: WizardTab.java   Source Code and License 5 votes vote down vote up
/**
 * The size of the tree is now somewhat dynamic. It was getting lost in the
 * new big windows :)
 */
@Override
public void componentResized(ComponentEvent event)
{
	int treeWidth = (int) (panel.getSize().width * 0.25);
	if( treeWidth < MIN_TREE_WIDTH )
	{
		treeWidth = MIN_TREE_WIDTH;
	}
	else if( treeWidth > MAX_TREE_WIDTH )
	{
		treeWidth = MAX_TREE_WIDTH;
	}
	guiLayout.setColumns(new int[]{treeWidth, TableLayout.FILL});
}
 
Example 26
Project: monarch   File: SequenceDiagram.java   Source Code and License 5 votes vote down vote up
public MemberAxis() {
  setPreferredSize(new Dimension(getWidth(), AXIS_SIZE));
  SequenceDiagram.this.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      int newWidth = e.getComponent().getWidth();
      setPreferredSize(new Dimension(newWidth, AXIS_SIZE));
      revalidate();
    }
  });
}
 
Example 27
Project: gate-core   File: ProgressPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void componentResized(ComponentEvent e) {
  int width = Math.min(400, (int)(getSize().width * (2f / 3)));
  progressTotal.setMaximumSize(new Dimension(width, progressTotal
          .getPreferredSize().height));
  progressSingle.setMaximumSize(new Dimension(width, progressSingle
          .getPreferredSize().height));
}
 
Example 28
Project: rapidminer   File: GUIInputHandler.java   Source Code and License 5 votes vote down vote up
@Override
public String inputPassword(String messageText) {
	final JPasswordField passwordField = new JPasswordField();
	JOptionPane jop = new JOptionPane(new Object[] { messageText, passwordField }, JOptionPane.QUESTION_MESSAGE,
			JOptionPane.OK_CANCEL_OPTION);
	JDialog dialog = jop.createDialog("Auhtentication required");
	dialog.addComponentListener(new ComponentAdapter() {

		@Override
		public void componentShown(ComponentEvent e) {
			SwingUtilities.invokeLater(new Runnable() {

				@Override
				public void run() {
					passwordField.requestFocusInWindow();
					passwordField.requestFocus();
				}
			});
		}
	});
	dialog.setVisible(true);
	int result = (Integer) jop.getValue();
	if (result == JOptionPane.OK_OPTION) {
		return new String(passwordField.getPassword());
	} else {
		return null;
	}
}
 
Example 29
Project: TrabalhoFinalEDA2   File: mxGraphOutline.java   Source Code and License 5 votes vote down vote up
public void componentResized(ComponentEvent e)
{
	if (updateScaleAndTranslate())
	{
		repaintBuffer = true;
		updateFinder(false);
		repaint();
	}
	else
	{
		updateFinder(true);
	}
}
 
Example 30
Project: org.alloytools.alloy   File: SimpleGUI.java   Source Code and License 4 votes vote down vote up
/** Called when this window is shown. */
public void componentShown(ComponentEvent e) {}
 
Example 31
Project: litiengine   File: ScreenManager.java   Source Code and License 4 votes vote down vote up
@Override
public void componentResized(final ComponentEvent evt) {
  resolution = getRenderComponent().getSize();
  ScreenManager.this.resolutionChangedConsumer.forEach(consumer -> consumer.accept(ScreenManager.this.getSize()));
}
 
Example 32
Project: VISNode   File: JNodeContainer.java   Source Code and License 4 votes vote down vote up
@Override
public void componentMoved(ComponentEvent e) {
    revalidate();
}
 
Example 33
Project: VISNode   File: JNodeContainer.java   Source Code and License 4 votes vote down vote up
@Override
public void componentShown(ComponentEvent e) {
    revalidate();
}
 
Example 34
Project: VISNode   File: JNodeContainer.java   Source Code and License 4 votes vote down vote up
@Override
public void componentHidden(ComponentEvent e) {
    revalidate();
}
 
Example 35
Project: OpenJSharp   File: InputContext.java   Source Code and License 4 votes vote down vote up
public void componentShown(ComponentEvent e) {
    notifyClientWindowChange((Window)e.getComponent());
}
 
Example 36
Project: Manns-Game-of-Life-Updated-Version   File: MGoL_Backend.java   Source Code and License 4 votes vote down vote up
@Override
public void componentMoved(ComponentEvent e) {}
 
Example 37
Project: Manns-Game-of-Life-Updated-Version   File: MGoL_Backend.java   Source Code and License 4 votes vote down vote up
@Override
public void componentShown(ComponentEvent e) {}
 
Example 38
Project: 2D-Elliptic-Mesh-Generator   File: PlotCanvas.java   Source Code and License 4 votes vote down vote up
public void componentMoved(ComponentEvent e) {
}
 
Example 39
Project: incubator-netbeans   File: ComponentWidget.java   Source Code and License 4 votes vote down vote up
public void componentResized (ComponentEvent e) {
    revalidate ();
}
 
Example 40
Project: Equella   File: WizardTab.java   Source Code and License 4 votes vote down vote up
@Override
public void componentMoved(ComponentEvent componentevent)
{
	// Nothing to do here
}