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); }
Dimension ss = Toolkit.getDefaultToolkit ().getScreenSize (); Dimension frameSize = new Dimension ( 500, 300 ); JFrame frame = new JFrame (); frame.setBounds ( ss.width / 2 - frameSize.width / 2, ss.height / 2 - frameSize.height / 2, frameSize.width, frameSize.height ); frame.setVisible ( true );
frame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE ); frame.setBounds ( sb.x + sb.width / 2 - frameSize.width / 2, sb.y + sb.height / 2 - frameSize.height / 2, frameSize.width, frameSize.height ); frame.setVisible ( true );
/** Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setTitle("Planet Render"); frame.setBounds(100, 100, 1200, 700); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new AppContent()); } }
/** * Constructor to run this application in a stand-alone window. * * @param ownerFrame the frame the application will be displayed in * @throws S3ServiceException */ public Uploader(JFrame ownerFrame, Properties standAloneArgumentProperties) throws S3ServiceException { this(false); this.ownerFrame = ownerFrame; this.standAloneArgumentProperties = standAloneArgumentProperties; init(); ownerFrame.getContentPane().add(this); ownerFrame.setBounds(this.getBounds()); ownerFrame.setVisible(true); }
/** * Return a temporary frame if the real frame owner is not yet set * (for example, */ private Frame getEmergencyDialogOwner() { JFrame emergencyFrame = new JFrame(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int screenWidth = (int) screenSize.getWidth(); int screenHeight = (int) screenSize.getHeight(); emergencyFrame.setBounds(screenWidth / 16, screenHeight / 16, screenWidth * 7 / 8, screenHeight * 7 / 8); return emergencyFrame; }
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setBounds(0, 0, 300, 400); frame.setLayout(null); final JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab("One", new JPanel()); tabbedPane.addTab("Two", new JPanel()); tabbedPane.addTab("Three", new JPanel()); tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Tab: " + tabbedPane.getSelectedIndex()); } }); tabbedPane.setBounds(0, 0, 300, 400); frame.add(tabbedPane); frame.setVisible(true); }
JFrame start = new JFrame("TatteredLands"); start.setVisible(true); start.setBounds(0, 0, width, height); // add other initialization operations here...
JFrame myFrame = new JFrame("My Frame"); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) myFrame.setBounds(10, 10, 300, 100); myFrame.setUndecorated(true);
/** * Constructor to run this application in a stand-alone window. * * @param ownerFrame the frame the application will be displayed in * @throws S3ServiceException */ public Cockpit(JFrame ownerFrame) throws S3ServiceException { this(); this.ownerFrame = ownerFrame; isStandAloneApplication = true; init(); ownerFrame.getContentPane().add(this); ownerFrame.setBounds(this.getBounds()); ownerFrame.setVisible(true); }
JFrame frame = new JFrame(); frame.setBounds(100, 100, 529, 300); frame.getContentPane().setLayout(null);//over ride default Container c = frame.getContentPane(); JButton btnNewButton_4 = new JButton("New button"); c.add(btnNewButton_4); c.seBounds(4,10,40,25); JButton btnNewButton_3 = new JButton("New button 3"); c.add(btnNewButton_3); c.seBounds(40,10,40,25);//...etc
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(); }
public class MainGui { private JFrame top; public MainGui(ActionListener listener) { top = new JFrame(); top.setBounds(300, 300, 600, 300); JButton doneButton = new JButton("Done"); doneButton.addActionListener(listener); top.add(doneButton); top.pack(); top.setVisible(true); } }
JFrame frame = new JFrame(); frame.setBounds(100, 100, 784, 533); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Use whatever layout suits you but I prefer mig frame.getContentPane().setLayout(new MigLayout("", "[344.00,grow,fill][-457.00]", "[grow]")); frame.setTitle("Title"); frame.setAlwaysOnTop(true); JPanel panel = new JPanel(); frame.getContentPane().add(panel, "cell 0 0,grow"); // Then add Text fields and labels so the user knows what to enter JLabel lbl = new JLabel("Environment Name"); panel .add(lbl, "cell 0 0"); JTextField textField = new JTextField(); panel.add(textField , "cell 0 1,growx");
/** * Constructor to run this application in a stand-alone window. * * @param ownerFrame the frame the application will be displayed in * @throws S3ServiceException */ public Cockpit(JFrame ownerFrame) throws S3ServiceException { this(); this.ownerFrame = ownerFrame; isStandAloneApplication = true; init(); ownerFrame.getContentPane().add(this); ownerFrame.setBounds(this.getBounds()); ownerFrame.setVisible(true); }
PopupFactory factory = PopupFactory.getSharedInstance(); JFrame frame = new JFrame(); frame.setLayout(null); frame.setBounds(428, 99, 185, 155); final JButton button = new JButton(); button.setText("Button"); button.setBounds(10, 93, 111, 25); frame.getContentPane().add(button); final Popup popup = factory.getPopup(null, frame, 200, 200); popup.show();
stomp_client.subscribe(clients_dest); mainFrame=new JFrame(); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel=new DrawPanel(false); panel.setBackground(background_color); mainFrame.pack(); mainFrame.setLocation(15, 25); mainFrame.setBounds(new Rectangle(250, 250)); mainFrame.setVisible(true); setTitle();
JFrame snakeFrame = new JFrame(); snakeFrame.setBounds(100, 200, 800, 800); snakeFrame.setVisible(true); snakeFrame.add(new JLabel(new ImageIcon("Images/Snake.png"))); snakeFrame.pack();
import java.awt.BorderLayout; public class MyFrame { JFrame frame; private JTable table; public MyFrame() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); table = new JTable(); table.setModel(new MyTableModel()); table.setFillsViewportHeight(true); table.getColumnModel() .getColumn(1) .setCellRenderer(new MyPanelCellRenderer()); table.setRowHeight(40); // static sizing JScrollPane scrollPane = new JScrollPane(); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); scrollPane.setViewportView(table); } }
/** * Constructor to run this application in a stand-alone window. * * @param ownerFrame the frame the application will be displayed in * @throws S3ServiceException */ public CockpitLite(JFrame ownerFrame, Properties standAloneArgumentProperties) throws S3ServiceException { mCredentialProvider = new BasicCredentialsProvider(); this.ownerFrame = ownerFrame; this.standAloneArgumentProperties = standAloneArgumentProperties; isStandAloneApplication = true; init(); ownerFrame.getContentPane().add(this); ownerFrame.setBounds(this.getBounds()); ownerFrame.setVisible(true); }