Search in sources :

Example 36 with JComponent

use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.

the class BMPCompressionTest method showDiff.

private static void showDiff(final BufferedImage in, final BufferedImage out) {
    final int width = in.getWidth();
    final int height = in.getHeight();
    JFrame f = new JFrame("");
    f.getContentPane().add(new JComponent() {

        public Dimension getPreferredSize() {
            return new Dimension(2 * width + 2, height);
        }

        public void paintComponent(Graphics g) {
            g.setColor(Color.black);
            g.drawImage(in, 0, 0, null);
            g.drawImage(out, width + 2, 0, null);
        }
    });
    f.pack();
    f.setVisible(true);
}
Also used : Graphics(java.awt.Graphics) JFrame(javax.swing.JFrame) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension)

Example 37 with JComponent

use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.

the class bug7170310 method check.

private static void check() {
    try {
        JViewport vp = null;
        for (Component c : tabbedPane.getComponents()) {
            if (c instanceof JViewport) {
                vp = (JViewport) c;
                break;
            }
        }
        JComponent v = (JComponent) vp.getView();
        Rectangle vr = vp.getViewRect();
        Dimension vs = v.getSize();
        // The tab view must be scrolled to the end so that the last tab is visible
        if (vs.width != (vr.x + vr.width)) {
            throw new RuntimeException("tabScroller.tabPanel view is positioned incorrectly: " + vs.width + " vs " + (vr.x + vr.width));
        }
    } catch (Exception e) {
        exception = e;
    }
}
Also used : JViewport(javax.swing.JViewport) JComponent(javax.swing.JComponent) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 38 with JComponent

use of javax.swing.JComponent in project jna by java-native-access.

the class WindowUtilsTest method xtestReveal.

public void xtestReveal() throws Exception {
    final int SIZE = 200;
    System.setProperty("sun.java2d.noddraw", "true");
    GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
    Window w;
    Container content;
    if (true) {
        JFrame frame = new JFrame(getName(), gconfig);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        content = frame.getContentPane();
        w = frame;
    } else {
        Frame frame = JOptionPane.getRootFrame();
        JWindow window = new JWindow(frame, gconfig);
        content = window.getContentPane();
        w = window;
    }
    final Window f = w;
    WindowUtils.setWindowTransparent(f, true);
    content.add(new JButton("Quit") {

        private static final long serialVersionUID = 1L;

        {
            addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            });
        }
    }, BorderLayout.SOUTH);
    content.add(new JComponent() {

        private static final long serialVersionUID = 1L;

        public Dimension getPreferredSize() {
            return new Dimension(SIZE, SIZE);
        }

        protected void paintComponent(Graphics graphics) {
            Graphics2D g = (Graphics2D) graphics.create();
            g.setComposite(AlphaComposite.Clear);
            g.fillRect(0, 0, SIZE, SIZE);
            g.dispose();
            g = (Graphics2D) graphics.create();
            Color[] colors = { new Color(0, 0, 0), new Color(0, 0, 0, 128), new Color(128, 128, 128), new Color(128, 128, 128, 128), new Color(255, 255, 255), new Color(255, 255, 255, 128) };
            for (int i = 0; i < colors.length; i++) {
                g.setColor(colors[i]);
                g.fillRect((SIZE * i) / colors.length, 0, (SIZE + colors.length - 1) / colors.length, SIZE);
            }
            g.setColor(Color.red);
            g.drawRect(0, 0, SIZE - 1, SIZE - 1);
            g.dispose();
            SwingUtilities.getWindowAncestor(this).toFront();
        }
    });
    f.pack();
    f.addMouseListener(handler);
    f.addMouseMotionListener(handler);
    f.setLocation(100, 100);
    f.setVisible(true);
    while (f.isVisible()) {
        Thread.sleep(1000);
    //f.repaint();
    }
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) ActionEvent(java.awt.event.ActionEvent) JWindow(javax.swing.JWindow) Color(java.awt.Color) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame)

Example 39 with JComponent

use of javax.swing.JComponent in project jna by java-native-access.

the class WindowUtilsTest method xtestWindowTransparency.

// Expect failure on windows and x11, since transparent pixels are not 
// properly captured by java.awt.Robot
public void xtestWindowTransparency() throws Exception {
    if (GraphicsEnvironment.isHeadless())
        return;
    System.setProperty("sun.java2d.noddraw", "true");
    GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
    Frame root = JOptionPane.getRootFrame();
    final Window background = new Window(root);
    background.setBackground(Color.white);
    background.setLocation(X, Y);
    final JWindow transparent = new JWindow(root, gconfig);
    transparent.setLocation(X, Y);
    ((JComponent) transparent.getContentPane()).setOpaque(false);
    transparent.getContentPane().add(new JComponent() {

        private static final long serialVersionUID = 1L;

        public Dimension getPreferredSize() {
            return new Dimension(W, H);
        }

        protected void paintComponent(Graphics g) {
            g = g.create();
            g.setColor(Color.red);
            g.fillRect(getWidth() / 4, getHeight() / 4, getWidth() / 2, getHeight() / 2);
            g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
            g.dispose();
        }
    });
    transparent.addMouseListener(handler);
    transparent.addMouseMotionListener(handler);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            background.pack();
            background.setSize(new Dimension(W, H));
            background.setVisible(true);
            transparent.pack();
            transparent.setSize(new Dimension(W, H));
            transparent.setVisible(true);
            transparent.toFront();
        }
    });
    WindowUtils.setWindowTransparent(transparent, true);
    //robot.delay(60000);
    Color sample = robot.getPixelColor(X + W / 2, Y + H / 2);
    assertEquals("Painted pixel should be opaque", Color.red, sample);
    sample = robot.getPixelColor(X + 10, Y + 10);
    assertEquals("Unpainted pixel should be transparent", Color.white, sample);
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) Graphics(java.awt.Graphics) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) JWindow(javax.swing.JWindow) Color(java.awt.Color) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 40 with JComponent

use of javax.swing.JComponent in project intellij-community by JetBrains.

the class LazyUiDisposable method showNotify.

public final void showNotify() {
    JComponent ui = myUI.getAndSet(null);
    if (ui == null)
        return;
    Project project = null;
    Disposable parent = myParent;
    if (ApplicationManager.getApplication() != null) {
        DataContext context = DataManager.getInstance().getDataContext(ui);
        project = PROJECT.getData(context);
        if (parent == null) {
            parent = UI_DISPOSABLE.getData(context);
        }
    }
    if (parent == null) {
        if (project == null) {
            Logger.getInstance(LazyUiDisposable.class).warn("use application as a parent disposable");
            parent = Disposer.get("ui");
        } else {
            Logger.getInstance(LazyUiDisposable.class).warn("use project as a parent disposable");
            parent = project;
        }
    }
    initialize(parent, myChild, project);
    Disposer.register(parent, myChild);
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) JComponent(javax.swing.JComponent)

Aggregations

JComponent (javax.swing.JComponent)225 Component (java.awt.Component)44 JPanel (javax.swing.JPanel)37 JLabel (javax.swing.JLabel)34 JButton (javax.swing.JButton)28 BorderLayout (java.awt.BorderLayout)27 Dimension (java.awt.Dimension)23 Insets (java.awt.Insets)20 ActionEvent (java.awt.event.ActionEvent)16 ArrayList (java.util.ArrayList)16 ActionListener (java.awt.event.ActionListener)15 Color (java.awt.Color)13 GridBagConstraints (java.awt.GridBagConstraints)13 Point (java.awt.Point)13 GridBagLayout (java.awt.GridBagLayout)12 JScrollPane (javax.swing.JScrollPane)12 JTextField (javax.swing.JTextField)12 JFrame (javax.swing.JFrame)11 Container (java.awt.Container)8 FlowLayout (java.awt.FlowLayout)8