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);
}
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;
}
}
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();
}
}
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);
}
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);
}
Aggregations