public static void main(String[] args) { Rectangle box = new Rectangle(5, 10, 20, 30); // New stuff - Create a program window and set it up. JFrame window = new JFrame(); // Tell Swing to exit the program when the program window is closed. window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set the window boundaries to be 300x300 on the screen, and position it 30 pixels from the top and left edges of the monitor. window.setBounds(30, 30, 300, 300); // Get the content pane of the window, and give it our own custom component. window.getContentPane().add(new JComponent() { // Not a typo - this is some advanced magic called an "anonymous class". Rectangle myBox = box; // Give the component a reference to our box object. public void paint(Graphics g) { g.drawRect(myBox.x, myBox.y, myBox.width, myBox.height); } }); // Make our window appear. window.setVisible(true); }
final Rectangle outsideStroke = new Rectangle(); outsideStroke.setLocation(rectangle.x, rectangle.y); outsideStroke.setSize(rectangle.width - BORDER_OFFSET / 2, rectangle.height - BORDER_OFFSET / 2); final Rectangle insideStroke = new Rectangle(); insideStroke.setLocation(rectangle.x + BORDER_OFFSET / 2, rectangle.y + BORDER_OFFSET / 2); insideStroke.setSize(rectangle.width - BORDER_OFFSET - BORDER_OFFSET / 2, graphics.draw(insideStroke); return new Dimension(rectangle.getSize());
public void go() throws Exception { if(!no_channel && !use_state) channel.connect(cluster_name); mainFrame=new JFrame(); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); panel=new DrawPanel(use_state); panel.setBackground(background_color); sub_panel=new JPanel(); mainFrame.getContentPane().add("Center", panel); clear_button=new JButton("Clear"); clear_button.setFont(default_font); clear_button.addActionListener(this); leave_button=new JButton("Leave"); leave_button.setFont(default_font); leave_button.addActionListener(this); sub_panel.add("South", clear_button); sub_panel.add("South", leave_button); mainFrame.getContentPane().add("South", sub_panel); mainFrame.setBackground(background_color); clear_button.setForeground(Color.blue); leave_button.setForeground(Color.blue); mainFrame.pack(); mainFrame.setLocation(15, 25); mainFrame.setBounds(new Rectangle(250, 250)); if(!no_channel && use_state) { channel.connect(cluster_name, null, state_timeout); } mainFrame.setVisible(true); setTitle(); }
final JPanel panel = new JPanel(new GridLayout(0,1)); JScrollPane scroll = new JScrollPane(panel); scroll.setPreferredSize(new Dimension(80,100)); gui.add(scroll, BorderLayout.CENTER); JButton addLabel = new JButton("Add Label"); gui.add(addLabel, BorderLayout.NORTH); ActionListener listener = new ActionListener() { int counter = 0; public void actionPerformed(ActionEvent ae) { panel.add(new JLabel("Label " + ++counter)); panel.revalidate(); int height = (int)panel.getPreferredSize().getHeight(); Rectangle rect = new Rectangle(0,height,10,10); panel.scrollRectToVisible(rect);
gui.add(l1); l2.setBackground(Color.YELLOW); l2.setOpaque(true); gui.add(l2); p1.add(new JLabel("Panel 1")); p1.setBorder(brdrRight); p1.setOpaque(false); if (parent!=null) { Color bg = parent.getBackground(); Rectangle rect = new Rectangle(0,0,width, height); Area borderRegion = new Area(rect); borderRegion.subtract(area);
JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); return new Dimension(200, 200); for (int row = 0; row < rowCount; row++) { for (int col = 0; col < columnCount; col++) { Rectangle cell = new Rectangle( xOffset + (col * cellWidth), yOffset + (row * cellHeight),
JScrollPane screenScroll = new JScrollPane(screenLabel); screenScroll.setPreferredSize(new Dimension( (int)(screen.getWidth()/3), (int)(screen.getHeight()/3))); panel.add(screenScroll, BorderLayout.CENTER); panel.add(selectionLabel, BorderLayout.SOUTH); public void mouseDragged(MouseEvent me) { Point end = me.getPoint(); captureRect = new Rectangle(start, new Dimension(end.x-start.x, end.y-start.y)); repaint(screen, screenCopy); screenLabel.repaint(); getScreenSize(); final BufferedImage screen = robot.createScreenCapture( new Rectangle(screenSize));
JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new TestPane()); Area area = new Area(new Rectangle(width, height)); area.subtract(new Area(new Rectangle(width - (shadowSize * 2), height - (shadowSize * 2)))); area = new Area(new Rectangle(width - (shadowSize * 2), height - (shadowSize * 2))); g2d.setColor(c.getBackground()); g2d.fill(area);
/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); combatArea = new javax.swing.JPanel(); setResizable(true); setTitle("Combat"); setNormalBounds(new java.awt.Rectangle(400, 200, 410, 307)); setVisible(true); getContentPane().setLayout(new java.awt.BorderLayout()); jScrollPane1.setViewportView(combatArea); getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); pack(); }// </editor-fold>//GEN-END:initComponents
int h = Integer.parseInt(p.getProperty("h")); Rectangle r = new Rectangle(x,y,w,h); final JFrame f = new JFrame("Good Location & Size"); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { f.add(ta); f.pack(); f.setLocationByPlatform(true); f.setVisible(true);
private void createShadowPicture(BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); int extra = 0; if (System.getProperty("os.name").equalsIgnoreCase("Windows XP")) { extra = 14; // Only create shadow if Windows XP (avoids double shadow in Mac OS; not tested for other OSes) } setSize(new Dimension(width + extra, height + extra)); setLocationRelativeTo(null); Rectangle windowRect = getBounds(); splash = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) splash.getGraphics(); try { Robot robot = new Robot(getGraphicsConfiguration().getDevice()); BufferedImage capture = robot.createScreenCapture(new Rectangle(windowRect.x, windowRect.y, windowRect.width + extra, windowRect.height + extra)); g2.drawImage(capture, null, 0, 0); } catch (AWTException e) { } BufferedImage shadow = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); Graphics g = shadow.getGraphics(); g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f)); g.fillRoundRect(6, 6, width, height, 12, 12); g2.drawImage(shadow, getBlurOp(7), 0, 0); g2.drawImage(image, 0, 0, this); }
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // Your work goes here: Construct a rectangle and set the frame bounds Rectangle box = new Rectangle(10, 20, 30, 40); f.setBounds(box);
public StatisticResultFm(JFrame owner, String data) { super(owner, true); setBounds(new Rectangle(150, 150, 450, 350)); JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane, BorderLayout.CENTER); JTextArea textArea = new JTextArea(); textArea.setEditable(false); scrollPane.setViewportView(textArea); textArea.setText(data); }
stomp_client.subscribe(clients_dest); mainFrame=new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel=new DrawPanel(false); panel.setBackground(background_color); sub_panel=new JPanel(); mainFrame.getContentPane().add("Center", panel); clear_button=new JButton("Clear"); clear_button.setFont(default_font); sub_panel.add("South", clear_button); sub_panel.add("South", leave_button); mainFrame.getContentPane().add("South", sub_panel); mainFrame.setBackground(background_color); clear_button.setForeground(Color.blue); mainFrame.pack(); mainFrame.setLocation(15, 25); mainFrame.setBounds(new Rectangle(250, 250)); mainFrame.setVisible(true); setTitle();
closeButtonBounds = new Rectangle(image.getWidth() - closeButton.getWidth() - 5, 6, closeButton.getWidth(), closeButton.getHeight()); backgroundComponent.setRectangle(new Rectangle(0, 0, image.getWidth(), image.getHeight())); backgroundComponent.render(graphics); (int) closeButtonBounds.getX(), (int) closeButtonBounds.getY(), null); return new Dimension(image.getWidth(), image.getHeight());
final JFrame jFrameNoMax = new JFrame() { { setMaximizedBounds(new Rectangle(0, 0)); addWindowStateListener(new WindowStateListener() { public void windowStateChanged(final WindowEvent e) { if (e.getNewState() == MAXIMIZED_BOTH) { setExtendedState(NORMAL); } } }); } }; // Tester jFrameNoMax.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); jFrameNoMax.setSize(300, 300); jFrameNoMax.setLocation(300, 300); jFrameNoMax.setVisible(true);
private static final int FRAMES = 24; private final Timer timer = new Timer(20, this); private final Rectangle rect = new Rectangle(); private BufferedImage background; private int index; JFrame f = new JFrame("AnimationTest"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(this); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); timer.start(); super(true); this.setOpaque(false); this.setPreferredSize(new Dimension(WIDE, HIGH)); this.addMouseListener(new MouseHandler()); this.addComponentListener(new ComponentHandler()); Dimension d = field.getPreferredSize(); field.setBounds(e.getX(), e.getY(), d.width, d.height); add(field);
final Dimension dimension = new Dimension( border.x + childDimensions.width + border.width, border.y + childDimensions.height + border.height); backgroundComponent.setRectangle(new Rectangle(dimension)); backgroundComponent.setBackgroundColor(backgroundColor); backgroundComponent.render(graphics); final Dimension childPreferredSize = new Dimension( preferredSize.width - border.x - border.width, preferredSize.height - border.y - border.height);