Java 8 Component - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Component class.

This code example shows how to use the following methods:addKeyListener, setSize, getPreferredSize
    
    
   public TextPropertyEditor()  { 
       super(); 
        
       textField = new JTextField(20);
        
       textField.setSize(textField.getPreferredSize());
 
       setSize(textField.getPreferredSize());       
       setActualSize(textField.getPreferredSize());
        
       add(textField);
        
       // allow the text editor to move as the user moves the edited target 
       //getTargetComponent().addFollower(this); 
        
       textField.addKeyListener(this);
       setFocusable(true); 
       setOpaque(true); 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addMouseMotionListener, getCursor, getLocation, getSize, setCursor
   public void mousePressed(MouseEvent e)
 
   { 
 
      source = e.getComponent();
      origin = source.getLocation();
 
      int width  = source.getSize().width  - dragInsets.left - dragInsets.right;
      int height = source.getSize().height - dragInsets.top - dragInsets.bottom;
 
      Rectangle r = new Rectangle(dragInsets.left, dragInsets.top, width, height);
 
      if (r.contains(e.getPoint()))
         setupForDragging(e);
 
   } 
 
 
 
   private void setupForDragging(MouseEvent e){

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground, getSelectionBackground, getSelectionForeground
	public Component getListCellRendererComponent(JList list, Object value, int i, boolean selected, boolean focused) {
 
		Webcam webcam = (Webcam) value;
 
		if (selected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else { 
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		} 
 
		setText(webcam.getName());
		setFont(list.getFont());
 
		return this;
	} 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addMouseMotionListener, getCursor, getLocation, getSize, setCursor
 
   { 
 
      source = e.getComponent();
 
      int width  = source.getSize().width  - dragInsets.left - dragInsets.right;
 
      int height = source.getSize().height - dragInsets.top - dragInsets.bottom;
 
      Rectangle r = new Rectangle(dragInsets.left, dragInsets.top, width, height);
 
 
 
      if (r.contains(e.getPoint()))
 
         setupForDragging(e);
 
   } 
 
 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getFont, getForeground, isEnabled, getSelectionBackground
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBackground, getForeground, getSelectionBackground, getSelectionForeground
	 */ 
	public Component getListCellRendererComponent(final JList list, final Object value, final int index,
	                                              final boolean isSelected, final boolean cellHasFocus) {
		Component cellRendererComponent = getCellRendererComponent(value, isSelected);
        if (isSelected) {
        	cellRendererComponent.setBackground(list.getSelectionBackground());
        	cellRendererComponent.setForeground(list.getSelectionForeground());
        } 
        else { 
        	cellRendererComponent.setBackground(list.getBackground());
        	cellRendererComponent.setForeground(list.getForeground());
        } 
		return cellRendererComponent;
	} 
	 
	private Component getCellRendererComponent(final Object value, final boolean isSelected) {
		final JComponent component;
		if (value == null) { 
			component =  new JLabel(noValueText);
		} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getFont, setFont, addCaretListener, getText
    SpinnerNumberModel  model;
     
    setLayout(new BorderLayout());
     
    // textarea 
    m_TextQuery = new JTextArea();
    m_TextQuery.addCaretListener(this);
    m_TextQuery.setFont(
        new Font("Monospaced", Font.PLAIN, m_TextQuery.getFont().getSize()));
    add(new JScrollPane(m_TextQuery), BorderLayout.CENTER);
 
    // buttons 
    panel = new JPanel(new BorderLayout());
    add(panel, BorderLayout.EAST);
    m_ButtonExecute.setMnemonic('E');
    m_ButtonExecute.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
	  execute(); 
	} 
      }); 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getHeight, getToolkit, getWidth, repaint, setLocation
     * 
     * @param component 
     *            the component you want to center in window 
     */ 
    public static void centerComponentInWindow(Component component) {
        Dimension dimension = component.getToolkit().getScreenSize();
 
        component.setLocation((int) ((dimension.getWidth() - component.getWidth()) / 2),
                (int) ((dimension.getHeight() - component.getHeight()) / 2));
        component.validate();
        component.repaint();
    } 
 
    /** 
     * Use this static method if you want to center a component over another 
     * component. 
     * 
     * @param parent 
     *            the component you want to use to place it on 
     * @param toBeCentered 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setSize, setPreferredSize
This code example shows how to use the following methods:addMouseListener, addMouseMotionListener, addMouseWheelListener
	} 
 
	public synchronized void register() { 
		resetCursorToCenter(); 
        if (component != null) {
            component.addMouseListener(this);
            component.addMouseMotionListener(this);
            component.addMouseWheelListener(this);
        } 
	} 
 
	public synchronized void unregister() { 
        if (component != null) {
            component.removeMouseListener(this);
            component.removeMouseMotionListener(this);
            component.removeMouseWheelListener(this);
        } 
	} 
 
	protected Component getComponent() {

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Component Questions & Answers:

See Code Examples for Java 8 Component Methods: