component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB ); Runnable r = new Runnable() { public void run() { final JFrame f = new JFrame("Test Screenshot"); p.add( new JScrollPane(new JTree()), BorderLayout.WEST ); p.add( new JScrollPane( new JTextArea(HELP,10,30) ), BorderLayout.CENTER ); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true);
constraints.fill = GridBagConstraints.BOTH; JLabel l = new JLabel("You have got 2 new Messages."); panel.add(l, constraints); constraints.gridx++; constraints.weightx = 0f; b.setMargin(new Insets(1, 4, 1, 4)); b.setFocusable(false); panel.add(b, constraints); dialog.setUndecorated(true); dialog.setSize(300, 100); dialog.setLocation(screenSize.width - dialog.getWidth(), screenSize.height - taskBarSize - dialog.getHeight()); lpg = new LinearGradientPaint(0, 0, 0, dialog.getHeight() / 2, new float[]{0f, 0.3f, 1f}, new Color[]{new Color(0.8f, 0.8f, 1f), new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f)});
Component c; // the component you would like to print to a BufferedImage JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setUndecorated(true); frame.getContentPane().add(c); frame.pack(); BufferedImage bi = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bi.createGraphics(); c.print(graphics); graphics.dispose(); frame.dispose();
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); p.add(f); frame.add(p); frame.setVisible(true); lastFocusableIndex = 0; sl.setFocused(false); autoSuggestionPopUpWindow.setVisible(false); setFocusToTextField(); autoSuggestionPopUpWindow.setVisible(false); setFocusToTextField(); suggestionsPanel.add(suggestionLabel); windowY = container.getY() + textField.getY() + textField.getHeight() + autoSuggestionPopUpWindow.getMinimumSize().height; } else { windowY = container.getY() + textField.getY() + textField.getHeight() + autoSuggestionPopUpWindow.getHeight();
final int taskBarSize = scnMax.bottom; setLocation(screenSize.width - getWidth(), screenSize.height - taskBarSize - getHeight()); lpg = new LinearGradientPaint(0, 0, 0, getHeight() / 2, new float[] { 0f, 0.3f, 1f }, new Color[] { new Color(0.8f, 0.8f, 1f), new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f) }); l.setOpaque(false); c.add(l, constraints); b.setFocusable(false); c.add(b, constraints);
JFrame f = new JFrame("LowerRightFrame"); f.add(new JPanel() { f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds(); int x = (int) rect.getMaxX() - f.getWidth(); int y = (int) rect.getMaxY() - f.getHeight(); f.setLocation(x, y); f.setVisible(true);
if (useSlideButton) { final JPanel statusPanel = new JPanel(); basePanel.add(statusPanel, BorderLayout.SOUTH); statusPanel.add(new JButton("Slide Left") { private static final long serialVersionUID = 9204819004142223529L; statusPanel.add(new JButton("Slide Right") { componentNew = jPanels.get(0); final int w = componentOld.getWidth(); final int h = componentOld.getHeight(); final Point p1 = componentOld.getLocation(); final Point p2 = new Point(0, 0); int step = 0; if ((slideType == LEFT) || (slideType == RIGHT)) { step = (int) (((float) parent.getWidth() / (float) Toolkit.getDefaultToolkit().getScreenSize().width) * 40.f); step = (int) (((float) parent.getHeight() / (float) Toolkit.getDefaultToolkit().getScreenSize().height) * 20.f);
private void recenterMouse(final Component component) { if (robot != null) { eventsSinceRecenter = 0; isRecentering = true; centerLocation.setLocation(component.getWidth() / 2, component.getHeight() / 2); centerLocationOnScreen.setLocation(centerLocation); SwingUtilities.convertPointToScreen(centerLocationOnScreen, component); robot.mouseMove(centerLocationOnScreen.x, centerLocationOnScreen.y); } }
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.add(jsp); frame.setVisible(true); BufferedImage bi = componentToImage(imagePanel, true); try { BufferedImage img = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TRANSLUCENT); Graphics2D g2d = (Graphics2D) img.getGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); component.setSize(component.getPreferredSize()); layoutComponent(component); BufferedImage img = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TRANSLUCENT); CellRendererPane crp = new CellRendererPane(); crp.add(component); crp.paintComponent(img.createGraphics(), component, crp, component.getBounds()); return img;
import javax.swing.*; import java.awt.*; public class TestFrameSize { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.setSize(new Dimension(450, 400)); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // frame.setLayout(new BorderLayout()); JLabel question = new JLabel("But that's whole code... Those 3 lines are whole code "); question.setHorizontalAlignment(JLabel.CENTER); frame.add(question); frame.setVisible(true); System.out.println(frame.getWidth() + " : " + frame.getHeight()); } }
"dialog decoration."); p.add(l); getContentPane().add(p, BorderLayout.CENTER); p.add(b); getContentPane().add(p, BorderLayout.SOUTH); int w = Math.max(240, getWidth() + 32), h = getHeight(); Point loc = new Point( owner.getLocationOnScreen().x + (owner.getWidth() - w) / 2, owner.getLocationOnScreen().y + (owner.getHeight() - w) * 2 / 3);
import Utilities.*; import javax.swing.*; import javax.imageio.*; import java.awt.*; import java.awt.image.*; import java.io.*; public class GradientMask { public static void main(String[] args) throws Exception{ JFrame Main = new JFrame("Gradient Mask"); JLabel imageLayer = new JLabel(); JLabel maskLayer = new JLabel(); BufferedImage image = ImageIO.read(new File("C:\\Users\\"+System.getenv("username")+"\\Desktop\\Cat Image.jpg")); BufferedImage gradientMask = new GradientImage(image.getWidth(), image.getHeight(), new Color[]{new Color(255, 255, 255, 125), Color.BLACK}, GradientImage.RADIAL_FROM_CENTER).getImage(); Main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Main.setBounds(100, 50, image.getWidth(), image.getHeight()); imageLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); maskLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); imageLayer.setIcon(new ImageIcon((Image) image)); maskLayer.setIcon(new ImageIcon((Image) gradientMask)); Main.getContentPane().add(imageLayer); imageLayer.add(maskLayer); Main.setVisible(true); } }
public ProgressDialog(Component parent, int steps, String string) { setTitle("Exporting file..."); setModal(true); this.exception = null; this.progress = 0; getContentPane().setLayout(new BorderLayout()); JPanel center = new JPanel(new GridLayout(2, 1)); progressBar = new JProgressBar(0, steps); center.add(progressBar); label = new JLabel(string); center.add(label); getContentPane().add(center, BorderLayout.CENTER); JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancel(); } }); buttons.add(cancel); getContentPane().add(buttons, BorderLayout.SOUTH); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); pack(); if (parent != null) { Point pLoc = parent.getLocation(); setLocation(pLoc.x + parent.getWidth() / 2 - getWidth() / 2, pLoc.y + parent.getHeight() / 2 - getHeight() / 2); } }
public static Point keepComponentInsideParent(Point l, Point parentPoint, Component c, Component parent) { int dx = parentPoint.x + parent.getWidth() - DEFAULT_INSETS.right - COMPONENT_INSETS.right; if (l.x + c.getWidth() > dx) { l.x = dx - c.getWidth(); } int dy = parentPoint.y + parent.getHeight() - DEFAULT_INSETS.bottom - COMPONENT_INSETS.bottom; if (l.y + c.getHeight() > dy) { l.y = Math.max(10, dy - c.getHeight()); } return l; }
import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.EmptyBorder; public class ALineBorder { public static void main(String args[]) { JFrame frame = new JFrame("Line Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Button1"); button1.setBorder( new EmptyBorder( 8, 8, 8, 8 ) ); JButton button2 = new JButton("Button2"); JButton button3 = new JButton("Button3"); button3.setBorder( new EmptyBorder( 16, 16, 16, 16 ) ); Container contentPane = frame.getContentPane(); contentPane.add(button1, BorderLayout.WEST); contentPane.add(button2, BorderLayout.CENTER); contentPane.add(button3, BorderLayout.EAST); frame.pack(); frame.setSize(300, frame.getHeight()); frame.setVisible(true); } }