java.awt.Component Java Examples
The following examples show how to use
java.awt.Component.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectivePanel.java From triplea with GNU General Public License v3.0 | 6 votes |
@Override public Component getTableCellRendererComponent( final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { adaptee.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); final JLabel renderer = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); renderer.setHorizontalAlignment(SwingConstants.CENTER); if (value == null) { renderer.setBorder(BorderFactory.createEmptyBorder()); } else if (value.toString().contains("T")) { renderer.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.green)); } else if (value.toString().contains("U")) { renderer.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.blue)); } else if (value.toString().contains("u")) { renderer.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.cyan)); } else { renderer.setBorder(BorderFactory.createEmptyBorder()); } return renderer; }
Example #2
Source File: MotifBorders.java From JDKSourceCode1.8 with MIT License | 6 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if (c instanceof AbstractButton) { AbstractButton b = (AbstractButton)c; ButtonModel model = b.getModel(); if (model.isArmed() && model.isPressed() || model.isSelected()) { drawBezel(g, x, y, width, height, (model.isPressed() || model.isSelected()), b.isFocusPainted() && b.hasFocus(), shadow, highlight, darkShadow, focus); } else { drawBezel(g, x, y, width, height, false, b.isFocusPainted() && b.hasFocus(), shadow, highlight, darkShadow, focus); } } else { drawBezel(g, x, y, width, height, false, false, shadow, highlight, darkShadow, focus); } }
Example #3
Source File: TimeSeriesAssistantPage_ReprojectingSources.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override protected Component createPageComponent() { final PropertyChangeListener listener = evt -> getContext().updateState(); collocationCrsForm = new MyCollocationCrsForm(SnapApp.getDefault().getAppContext(), listener, getAssistantModel()); collocationCrsForm.addMyChangeListener(); final JPanel pagePanel = new JPanel(new BorderLayout()); final JPanel northPanel = new JPanel(new BorderLayout()); northPanel.add(new JLabel("Use CRS of "), BorderLayout.WEST); northPanel.add(collocationCrsForm.getCrsUI()); pagePanel.add(northPanel, BorderLayout.NORTH); final JPanel southPanel = new JPanel(new FlowLayout()); errorText = new JTextArea(); errorText.setBackground(southPanel.getBackground()); final JPanel jPanel = new JPanel(); jPanel.add(errorText); southPanel.add(errorText); pagePanel.add(southPanel, BorderLayout.SOUTH); return pagePanel; }
Example #4
Source File: JTitledPanel.java From netbeans with Apache License 2.0 | 6 votes |
protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) { if (!c.isEnabled()) { return; } Color oldColor = g.getColor(); int h = height; int w = width; g.translate(x, y); g.setColor(getHighlightInnerColor(c)); g.drawLine(0, 0, 0, h - 1); g.drawLine(1, 0, w - 1, 0); g.setColor(getShadowOuterColor(c)); g.drawLine(0, h - 1, w - 1, h - 1); g.drawLine(w - 1, 0, w - 1, h - 2); g.translate(-x, -y); g.setColor(oldColor); }
Example #5
Source File: ScrollPaneLayout.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Returns the <code>Component</code> at the specified corner. * @param key the <code>String</code> specifying the corner * @return the <code>Component</code> at the specified corner, as defined in * {@link ScrollPaneConstants}; if <code>key</code> is not one of the * four corners, <code>null</code> is returned * @see JScrollPane#getCorner */ public Component getCorner(String key) { if (key.equals(LOWER_LEFT_CORNER)) { return lowerLeft; } else if (key.equals(LOWER_RIGHT_CORNER)) { return lowerRight; } else if (key.equals(UPPER_LEFT_CORNER)) { return upperLeft; } else if (key.equals(UPPER_RIGHT_CORNER)) { return upperRight; } else { return null; } }
Example #6
Source File: CDropTarget.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private CDropTarget(DropTarget dropTarget, Component component, ComponentPeer peer) { super(); fDropTarget = dropTarget; fComponent = component; fPeer = peer; long nativePeer = CPlatformWindow.getNativeViewPtr(((LWComponentPeer) peer).getPlatformWindow()); if (nativePeer == 0L) return; // Unsupported for a window without a native view (plugin) // Create native dragging destination: fNativeDropTarget = this.createNativeDropTarget(dropTarget, component, peer, nativePeer); if (fNativeDropTarget == 0) { throw new IllegalStateException("CDropTarget.createNativeDropTarget() failed."); } }
Example #7
Source File: ISOTreeRenderer.java From ISO8583 with GNU General Public License v3.0 | 6 votes |
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean exp, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, exp, leaf, row, hasFocus); setOpenIcon(isoIcon); setClosedIcon(isoIcon); setLeafIcon(isoIcon); setFont(new Font("Arial", Font.PLAIN, 14)); if (!(((DefaultMutableTreeNode) value).getUserObject() instanceof String)) { GenericIsoVO isoVO = (GenericIsoVO) ((DefaultMutableTreeNode) value).getUserObject(); if (isoVO instanceof MessageVO) setIcon(validMessage); else setIcon(validField); } return this; }
Example #8
Source File: RSpinnerTest.java From marathonv5 with Apache License 2.0 | 6 votes |
public void listSpinnerWithInvalidValue() throws Throwable { final LoggingRecorder lr = new LoggingRecorder(); final Exception[] exc = new Exception[] { null }; siw(new Runnable() { @Override public void run() { List<Component> spinnerComponents = ComponentUtils.findComponents(JSpinner.class, frame); JSpinner listSpinner = (JSpinner) spinnerComponents.get(0); RSpinner rSpinner = new RSpinner(listSpinner, null, null, lr); rSpinner.focusGained(null); try { listSpinner.setValue("Ostrich\""); Call call = lr.getCall(); AssertJUnit.assertEquals("select", call.getFunction()); AssertJUnit.assertEquals("Ostrich\"", call.getState()); exc[0] = new MissingException(IllegalArgumentException.class); } catch (IllegalArgumentException e) { } rSpinner.focusLost(null); } }); if (exc[0] != null) { throw exc[0]; } }
Example #9
Source File: DeletePrompt.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override protected Component createContents() { deleteLoginCheck.setSelected(true); submit.addActionListener((e) -> this.submit()); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridy = 0; addLabelAndInput(panel, deleteLoginLabel, deleteLoginCheck, gbc); gbc.gridy++; gbc.gridx = 1; gbc.anchor = GridBagConstraints.NORTHEAST; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.NONE; panel.add(submit, gbc.clone()); return panel; }
Example #10
Source File: Test4619792.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws IntrospectionException { Class[] types = { Component.class, Container.class, JComponent.class, AbstractButton.class, JButton.class, JToggleButton.class, }; // Control set. "enabled" and "name" has the same pattern and can be found String[] names = { "enabled", "name", "focusable", }; for (String name : names) { for (Class type : types) { BeanUtils.getPropertyDescriptor(type, name); } } }
Example #11
Source File: JMenu.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Returns the nth Accessible child of the object. * * @param i zero-based index of child * @return the nth Accessible child of the object */ public Accessible getAccessibleChild(int i) { Component[] children = getMenuComponents(); int count = 0; for (Component child : children) { if (child instanceof Accessible) { if (count == i) { if (child instanceof JComponent) { // FIXME: [[[WDW - probably should set this when // the component is added to the menu. I tried // to do this in most cases, but the separators // added by addSeparator are hard to get to.]]] AccessibleContext ac = child.getAccessibleContext(); ac.setAccessibleParent(JMenu.this); } return (Accessible) child; } else { count++; } } } return null; }
Example #12
Source File: AncestorNotifier.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
void addListeners(Component ancestor, boolean addToFirst) { Component a; firstInvisibleAncestor = null; for (a = ancestor; firstInvisibleAncestor == null; a = a.getParent()) { if (addToFirst || a != ancestor) { a.addComponentListener(this); if (a instanceof JComponent) { JComponent jAncestor = (JComponent)a; jAncestor.addPropertyChangeListener(this); } } if (!a.isVisible() || a.getParent() == null || a instanceof Window) { firstInvisibleAncestor = a; } } if (firstInvisibleAncestor instanceof Window && firstInvisibleAncestor.isVisible()) { firstInvisibleAncestor = null; } }
Example #13
Source File: ProjectAttributesPanelVisual.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates new form NewProjectVisualPanel1 */ @SuppressWarnings("LeakingThisInConstructor") public ProjectAttributesPanelVisual(ProjectAttriburesPanel panel, Component bottomComponent) { this.panel = panel; initComponents(); if (bottomComponent != null) { pnlExtraSpace.add(bottomComponent); } tfProjectName.getDocument().addDocumentListener(this); tfProjectLocation.getDocument().addDocumentListener(this); tfGroup.getDocument().addDocumentListener(this); tfPackageBase.getDocument().addDocumentListener(this); }
Example #14
Source File: MainFrame.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private void enableMenu(final JMenu menu) { menu.setEnabled(true); for (final Component c : menu.getMenuComponents()) { if (c instanceof JMenu) { enableMenu((JMenu) c); } else if (c instanceof JMenuItem) { ((JMenuItem) c).setEnabled(true); } } }
Example #15
Source File: SynthToolBarUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private boolean isGlue(Component c) { if (c.isVisible() && c instanceof Box.Filler) { Box.Filler f = (Box.Filler)c; Dimension min = f.getMinimumSize(); Dimension pref = f.getPreferredSize(); return min.width == 0 && min.height == 0 && pref.width == 0 && pref.height == 0; } return false; }
Example #16
Source File: JLightweightFrame.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void updateClientCursor() { Point p = MouseInfo.getPointerInfo().getLocation(); SwingUtilities.convertPointFromScreen(p, this); Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y); if (target != null) { content.setCursor(target.getCursor()); } }
Example #17
Source File: SelectionColumnPanel.java From nextreports-designer with Apache License 2.0 | 5 votes |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value != null) { DBColumn column = (DBColumn) value; if (column.isPrimaryKey()) { comp.setIcon(primaryKeyIcon); comp.setText(column.getName()); } else if (column.isForeignKey()) { comp.setIcon(foreignKeyIcon); comp.setText(column.getName()); } else if (column.isIndex()) { comp.setIcon(indexKeyIcon); comp.setText(column.getName()); } else { comp.setIcon(columnIcon); comp.setText(column.getName()); } value = column.getName(); list.setToolTipText(value.toString()); } return comp; }
Example #18
Source File: DetailsTableCellRenderer.java From visualvm with GNU General Public License v2.0 | 5 votes |
protected void updateRenderer(Component c, JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (!isSelected) { c.setBackground(row % 2 == 0 ? DARKER_BACKGROUND : BACKGROUND); // Make sure the renderer paints its background (Nimbus) if (c instanceof JComponent) ((JComponent)c).setOpaque(true); } }
Example #19
Source File: Symbol.java From energy2d with GNU Lesser General Public License v3.0 | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { super.paintIcon(c, g, x, y); Graphics2D g2 = (Graphics2D) g; Rectangle2D.Float s = new Rectangle2D.Float(xSymbol + wSymbol * 0.4f, ySymbol + hSymbol * 0.3f, wSymbol * 0.4f, hSymbol * 0.4f); Arc2D.Float a = new Arc2D.Float(s, -90, 180, Arc2D.OPEN); g2.draw(a); int x0 = Math.round(xSymbol + wSymbol * 0.3f); int y0 = Math.round(ySymbol + hSymbol * 0.28f); g2.drawLine(Math.round(xSymbol + wSymbol * 0.55f), y0, x0, y0); g2.drawLine(x0, y0, x0 + 2, y0 - 2); g2.drawLine(x0, y0, x0 + 2, y0 + 2); y0 += Math.round(hSymbol * 0.4f); g2.drawLine(Math.round(xSymbol + wSymbol * 0.55f), y0, x0, y0); }
Example #20
Source File: TabPanelTow.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Adds the towing text label to the towing label panel. */ private void addTowingTextLabel() { try { Component lastComponent = towingLabelPanel.getComponent(1); if (lastComponent == towingButton) { towingLabelPanel.remove(towingButton); towingLabelPanel.add(towingTextLabel); } } catch (ArrayIndexOutOfBoundsException e) { towingLabelPanel.add(towingTextLabel); } }
Example #21
Source File: ResultsView.java From netbeans with Apache License 2.0 | 5 votes |
public final void removeView(Component view) { if (view == null) return; if (tabs != null) { int viewIndex = tabs.indexOfComponent(view); if (viewIndex == -1) return; if (tabs.getTabCount() > 2) { toolbars.remove(viewIndex); tabs.remove(view); } else { tabs.remove(view); firstView = tabs.getComponentAt(0); firstName = tabs.getTitleAt(0); firstIcon = tabs.getIconAt(0); firstDescription = tabs.getToolTipTextAt(0); remove(tabs); add(firstView); setToolbar(toolbars.get(0)); tabs = null; } } else if (firstView == view) { remove(firstView); setToolbar(null); toolbars.clear(); firstView = null; firstName = null; firstIcon = null; firstDescription = null; fireViewOrIndexChanged(); } }
Example #22
Source File: BevelBorder.java From JDKSourceCode1.8 with MIT License | 5 votes |
protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); int h = height; int w = width; g.translate(x, y); g.setColor(getHighlightOuterColor(c)); g.drawLine(0, 0, 0, h-2); g.drawLine(1, 0, w-2, 0); g.setColor(getHighlightInnerColor(c)); g.drawLine(1, 1, 1, h-3); g.drawLine(2, 1, w-3, 1); g.setColor(getShadowOuterColor(c)); g.drawLine(0, h-1, w-1, h-1); g.drawLine(w-1, 0, w-1, h-2); g.setColor(getShadowInnerColor(c)); g.drawLine(1, h-2, w-2, h-2); g.drawLine(w-2, 1, w-2, h-3); g.translate(-x, -y); g.setColor(oldColor); }
Example #23
Source File: SystemAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void paintIcon(Component c, Graphics g, int x, int y) { // When enabled, tracks color choices of container: comp.setBackground(c.getBackground()); comp.setForeground(c.getForeground()); Graphics clip = g.create(x, y, getIconWidth(), getIconHeight()); comp.paint(clip); }
Example #24
Source File: PullUpOperator.java From netbeans with Apache License 2.0 | 5 votes |
public void printComp(Container c, String s){ System.out.println(s + c.getClass().getName()); if(c instanceof Container){ for (Component com : c.getComponents()) { printComp((Container) com, s + "__"); } } }
Example #25
Source File: ArchiveUtils.java From ghidra with Apache License 2.0 | 5 votes |
public static boolean canClose(Archive archive, Component component) { if (!archive.isChanged()) { return true; } int result = OptionDialog.showYesNoCancelDialog(component, "Save Archive?", "Datatype Archive \"" + archive.getName() + "\" has been changed.\n Do you want to save the changes?"); if (result == OptionDialog.CANCEL_OPTION) { return false; } if (result == OptionDialog.NO_OPTION) { if (archive instanceof FileArchive) { // Release the write lock without saving. Returns file archive to its unedited state. try { ((FileArchive) archive).releaseWriteLock(); } catch (IOException e) { Msg.showError(log, component, "Unable to release File Archive write lock.", e.getMessage(), e); return false; } } return true; } return saveArchive(archive, component); }
Example #26
Source File: GraphicalDiffVisualizer.java From netbeans with Apache License 2.0 | 5 votes |
/** * Show the visual representation of the diff between two sources. * @param diffs The list of differences (instances of {@link Difference}). * may be <code>null</code> in case that it does not need diff provider. * @param name1 the name of the first source * @param title1 the title of the first source * @param r1 the first source * @param name2 the name of the second source * @param title2 the title of the second source * @param r2 the second resource compared with the first one. * @param MIMEType the mime type of these sources * @return The TopComponent representing the diff visual representation * or null, when the representation is outside the IDE. */ public Component createView(Difference[] diffs, String name1, String title1, Reader r1, String name2, String title2, Reader r2, String MIMEType) { if (diffs.length == 0) { DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(NbBundle.getMessage(GraphicalDiffVisualizer.class, "MSG_NoDifference", name1, name2))); } DiffComponent diff; String componentName = name1; if (name2 != null && name2.length() > 0) componentName = NbBundle.getMessage( GraphicalDiffVisualizer.class, "MSG_TwoFilesDiffTitle", componentName, name2); diff = new DiffComponent(diffs, componentName, MIMEType, name1, name2, title1, title2, r1, r2, new Color[] { colorMissing, colorAdded, colorChanged }); return diff; }
Example #27
Source File: SunVolatileImage.java From Bytecoder with Apache License 2.0 | 5 votes |
private SunVolatileImage(Component comp, GraphicsConfiguration graphicsConfig, int width, int height, Object context, ImageCapabilities caps) { this(comp, graphicsConfig, width, height, context, Transparency.OPAQUE, caps, UNDEFINED); }
Example #28
Source File: TSFrame.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void animateComponent(final Component comp) { Thread t = new Thread(new Runnable() { public void run() { do { try { Thread.sleep(50); } catch (InterruptedException ex) {} comp.repaint(); } while (!done); } }); t.start(); }
Example #29
Source File: MoveUIEffect.java From pumpernickel with MIT License | 5 votes |
public void stateChanged(ChangeEvent e) { Component comp = getComponent(); repaint(comp); float f = getProgress(); int x = Math.round(startingBounds.x * (1 - f) + finalBounds.x * f); int y = Math.round(startingBounds.y * (1 - f) + finalBounds.y * f); int width = Math.round(startingBounds.width * (1 - f) + finalBounds.width * f); int height = Math.round(startingBounds.height * (1 - f) + finalBounds.height * f); comp.setBounds(x, y, width, height); repaint(comp); }
Example #30
Source File: GroupLayout.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Forces the specified components to have the same size along the * specified axis regardless of their preferred, minimum or * maximum sizes. Components that are linked are given the maximum * of the preferred size of each of the linked components. For * example, if you link two components along the horizontal axis * and the preferred width is 10 and 20, both components are given * a width of 20. * <p> * This can be used multiple times to force any number of * components to share the same size. * <p> * Linked {@code Component}s are not be resizable. * * @param components the {@code Component}s that are to have the same size * @param axis the axis to link the size along; one of * {@code SwingConstants.HORIZONTAL} or * {@code SwingConstans.VERTICAL} * @throws IllegalArgumentException if {@code components} is * {@code null}, or contains {@code null}; or {@code axis} * is not {@code SwingConstants.HORIZONTAL} or * {@code SwingConstants.VERTICAL} */ public void linkSize(int axis, Component... components) { if (components == null) { throw new IllegalArgumentException("Components must be non-null"); } for (int counter = components.length - 1; counter >= 0; counter--) { Component c = components[counter]; if (components[counter] == null) { throw new IllegalArgumentException( "Components must be non-null"); } // Force the component to be added getComponentInfo(c); } int glAxis; if (axis == SwingConstants.HORIZONTAL) { glAxis = HORIZONTAL; } else if (axis == SwingConstants.VERTICAL) { glAxis = VERTICAL; } else { throw new IllegalArgumentException("Axis must be one of " + "SwingConstants.HORIZONTAL or SwingConstants.VERTICAL"); } LinkInfo master = getComponentInfo( components[components.length - 1]).getLinkInfo(glAxis); for (int counter = components.length - 2; counter >= 0; counter--) { master.add(getComponentInfo(components[counter])); } invalidateHost(); }