javax.swing.JFrame.setBounds()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(285)

本文整理了Java中javax.swing.JFrame.setBounds()方法的一些代码示例,展示了JFrame.setBounds()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.setBounds()方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名:setBounds

JFrame.setBounds介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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 );

代码示例来源:origin: stackoverflow.com

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 );

代码示例来源:origin: codeka/wwmmo

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

代码示例来源:origin: net.java.dev.jets3t/jets3t

/**
 * 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);
}

代码示例来源:origin: violetumleditor/violetumleditor

/**
 * 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;
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

JFrame start = new JFrame("TatteredLands");
 start.setVisible(true);
 start.setBounds(0, 0, width, height);
 // add other initialization operations here...

代码示例来源:origin: stackoverflow.com

JFrame myFrame = new JFrame("My Frame");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)       
myFrame.setBounds(10, 10, 300, 100);
myFrame.setUndecorated(true);

代码示例来源:origin: net.java.dev.jets3t/jets3t

/**
 * 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);
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: wildfly/wildfly

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: stackoverflow.com

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");

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jets3t

/**
 * 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);
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: wildfly/wildfly

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

代码示例来源:origin: stackoverflow.com

JFrame snakeFrame = new JFrame();
snakeFrame.setBounds(100, 200, 800, 800);
snakeFrame.setVisible(true);
snakeFrame.add(new JLabel(new ImageIcon("Images/Snake.png")));
snakeFrame.pack();

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: net.java.dev.jets3t/jets3t

/**
 * 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);
}

相关文章

JFrame类方法