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();
public SplitPane() { super("SplitPane example"); setDefaultCloseOperation(EXIT_ON_CLOSE); jsp.setDividerLocation(getWidth() / 2); setContentPane(jsp); setVisible(true);
return getPreferredSize().width < getParent().getWidth(); getContentPane().add( scrollPane ); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setSize(400, 300); frame.setVisible(true);
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);
import java.awt.Component; //import these 3 header files import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.JFrame; public class DC extends JFrame { public DC() { setSize(400, 300); setVisible(true); // if (getWidth() >= 1000) System.out.print("Thousand"); addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent evt) { Component c = (Component)evt.getSource(); if(c.getWidth()>=1000) //This will print Thousand { System.out.println("Thousand"); } } }); } public static void main(String[] args) { DC dc = new DC(); dc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
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); } }
public boolean getScrollableTracksViewportWidth() return getPreferredSize().width < getParent().getWidth(); if (tcm.getTotalColumnWidth() < getParent().getWidth()) setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); super.doLayout(); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(table)); frame.pack(); frame.setVisible(true);
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;
"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 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()); } }
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); } }