java.awt.Window.setBounds()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(220)

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

Window.setBounds介绍

暂无

代码示例

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

f.setBounds(r);
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);

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

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Test4 {

  protected static void initUI() {
    JFrame frame = new JFrame("test");
    frame.setBounds(0, 0, 300, 200);
    frame.setVisible(true);
    System.err.println(frame.getSize());
    frame.setResizable(false);
    System.err.println(frame.getSize());
  }

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {

      @Override
      public void run() {
        initUI();
      }
    });
  }
}

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

w.setBounds(w.getGraphicsConfiguration().getBounds());
w.setVisible(true);

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

import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Alignment;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.LayoutStyle.ComponentPlacement;import javax.swing.border.EmptyBorder;import javax.swing.filechooser.FileFilter;import javax.swing.filechooser.FileNameExtensionFilter;public class ConfigureDialog extends JDialog implements ActionListener{private static final long serialVersionUID=1L;private final JPanel contentPanel=new JPanel();private JTextField driverPathTextField;private JLabel lblDriverPath;private JButton btnBrowse;public static void main(String[]args){try{ConfigureDialog dialog=new ConfigureDialog(new JFrame());dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true);}catch(Exception e){e.printStackTrace();}}
public ConfigureDialog(JFrame parent){super(parent,"",true);if(parent!=null){Dimension parentSize=parent.getSize();Point p=parent.getLocation();setLocation(p.x+parentSize.width+100,p.y+parentSize.height/1);}
setBounds(100,100,479,141);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5,5,5,5));getContentPane().add(contentPanel,BorderLayout.CENTER);{lblDriverPath=new JLabel("Driver Path : ");}
{driverPathTextField=new JTextField(System.getProperty("web.ie.driver"));driverPathTextField.setColumns(10);}
btnBrowse=new JButton("Browse");GroupLayout gl_contentPanel=new GroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addContainerGap().addComponent(lblDriverPath).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(btnBrowse).addComponent(driverPathTextField,GroupLayout.DEFAULT_SIZE,207,Short.MAX_VALUE)).addContainerGap()));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(5).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(driverPathTextField,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE).addComponent(lblDriverPath)).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnBrowse).addContainerGap(21,Short.MAX_VALUE)));contentPanel.setLayout(gl_contentPanel);{JPanel buttonPane=new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane,BorderLayout.SOUTH);{JButton okButton=new JButton("OK");okButton.setActionCommand("OK");okButton.addActionListener(this);buttonPane.add(okButton);getRootPane().setDefaultButton(okButton);}
{JButton cancelButton=new JButton("Cancel");cancelButton.setActionCommand("Cancel");cancelButton.addActionListener(this);buttonPane.add(cancelButton);}}
btnBrowse.addActionListener(this);}@Override
public void actionPerformed(ActionEvent e){if("Cancel".contains(e.getActionCommand())){dispose();}else if("Browse".contains(e.getActionCommand())){JFileChooser fileopen=new JFileChooser();FileFilter filter=new FileNameExtensionFilter("exe file","exe");fileopen.addChoosableFileFilter(filter);fileopen.setAcceptAllFileFilterUsed(false);fileopen.setFileFilter(filter);fileopen.setFileSelectionMode(JFileChooser.FILES_ONLY);int ret=fileopen.showOpenDialog(this);if(ret==JFileChooser.APPROVE_OPTION){File file=fileopen.getSelectedFile();System.out.println(file);driverPathTextField.setText(file.getPath());}}else if("OK".contains(e.getActionCommand())){System.setProperty("web.ie.driver",driverPathTextField.getText());dispose();}}}

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

package btn;

import javax.swing.JFrame;

public class Frame extends JFrame
{
  public Frame()
  {
    super("Hello world test");
    this.setBounds(0, 0, 300, 500);
    this.add(new Button());
    this.setDefaultCloseOperation(Frame.EXIT_ON_CLOSE);
  }
}

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

import javax.swing.*;

public class MyFrame extends JFrame {

  public MyFrame()
  {
    setBounds(100, 100, 491, 310);
    getContentPane().setLayout(null);

    JTextArea textField = new JTextArea();
    textField.setEditable(false);

    String str = "";
    for (int i = 0; i < 50; ++i)
      str += "Some text\n";
    textField.setText(str);

    JScrollPane scroll = new JScrollPane(textField);
    scroll.setBounds(10, 11, 455, 249);                     // <-- THIS

    getContentPane().add(scroll);
    setLocationRelativeTo ( null );
  }
}

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

import java.awt.Frame;
Frame fullScreenFrame;
void setup(){
 fullScreenFrame = new  Frame();
 fullScreenFrame.setUndecorated(true);//prepare an undecorated fullscreen frame since java won't allow you to 'undecorate' a frame after it's been set visible 
 fullScreenFrame.setBounds(0,0,displayWidth,displayHeight);
 fullScreenFrame.addKeyListener(getKeyListeners()[0]);//pass key events from this applet to the fullScreen Frame
}
void draw(){
 background((float)mouseX/width * 255,(float)mouseY/height * 255,0);
}
void keyReleased(){
 if(key == 'f') {
   setBounds(0,0,displayWidth,displayHeight);//resize the skech
   fullScreenFrame.add(frame.getComponent(0));//add the applet to the fullscreen frame from Processing's frame
   fullScreenFrame.setVisible(true);//make our fullscreen frame visible
   frame.setVisible(false );//and hide Processing's frame
  }
}

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

import java.awt.Dialog;
import java.awt.Label;
import java.awt.Window;

public class Main {
 public static void main(String[] args) {
 Dialog d = new Dialog(((Window)null),"Hello world!");
 d.setBounds(0, 0, 180, 70);
 d.add(new Label("Hello world!"));
 d.setVisible(true);
 }
}

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

import java.lang.Runnable;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;

public class Window1 extends JFrame {

  public static void main(String... args){
    javax.swing.SwingUtilities.invokeLater(new java.lang.Runnable() {
      public void run() {
        Window1 window = new Window1();
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setBounds(200, 200, 400, 300);
        window.setVisible(true);
      }
    });
  }

}

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

jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds(new java.awt.Rectangle(0, 0, 0, 0));
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
layout.columnWidths = new int[] {0, 7, 0};
layout.rowHeights = new int[] {0, 7, 0, 7, 0};
getContentPane().setLayout(layout);
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
getContentPane().add(jLabel1, gridBagConstraints);
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
getContentPane().add(jTextField1, gridBagConstraints);
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
getContentPane().add(jLabel2, gridBagConstraints);
setVisible(true);
jTextField1.selectAll();
jTextField1.requestFocus();

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

private JPanel panel = new JPanel();
public displayFullScreen() {
  setUndecorated(true);
  panel.setLayout(new FlowLayout(FlowLayout.CENTER));
  alarmMessage.setText("Alarm !");
  alarmMessage.setFont(new Font("Cambria",Font.BOLD,100));
  alarmMessage.setForeground(Color.CYAN);
  panel.add(alarmMessage);
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  setBounds(0,0,screenSize.width,screenSize.height);
  panel.setBackground(Color.black);
  add(panel);

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

import javax.swing.JFrame;
import javax.swing.JButton;

public class Test {
 public static void main(String[] args) {
  JFrame f = new JFrame();
  f.setBounds(10, 10, 500, 200);
  JButton b1 = new JButton("b1");
  b1.addActionListener((c) -> {
   buttonPressed(f);
  });
  f.setContentPane(b1);
  f.setVisible(true);
 }

 private static void buttonPressed(JFrame f) {
  JButton b2 = new JButton("b2");
  f.setContentPane(b2);
  f.revalidate();
 }

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

Window w=new Window(null)
{
 @Override
 public void paint(Graphics g)
 {
  final Font font = getFont().deriveFont(48f);
  g.setFont(font);
  g.setColor(Color.RED);
  final String message = "Hello";
  FontMetrics metrics = g.getFontMetrics();
  g.drawString(message,
   (getWidth()-metrics.stringWidth(message))/2,
   (getHeight()-metrics.getHeight())/2);
 }
 @Override
 public void update(Graphics g)
 {
  paint(g);
 }
};
w.setAlwaysOnTop(true);
w.setBounds(w.getGraphicsConfiguration().getBounds());
w.setBackground(new Color(0, true));
w.setVisible(true);

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

import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jdesktop.swingx.JXDatePicker;

public class DatePickerExample extends JPanel {

  public static void main(String[] args) {
    JFrame frame = new JFrame("JXPicker Example");
    JPanel panel = new JPanel();

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(400, 400, 250, 100);

    JXDatePicker picker = new JXDatePicker();
    picker.setDate(Calendar.getInstance().getTime());
    picker.setFormats(new SimpleDateFormat("dd.MM.yyyy"));

    panel.add(picker);
    frame.getContentPane().add(panel);

    frame.setVisible(true);
  }
}

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

import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

import javax.swing.JFrame;

public class FenNoBorder extends JFrame {

  public FenNoBorder () {
    setUndecorated(true);
    setVisible(true);
    GraphicsEnvironment graphicsEnvironment=GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle maximumWindowBounds=graphicsEnvironment.getMaximumWindowBounds();
    setBounds(maximumWindowBounds);
  }
}

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

private static void initAndShowGUI() {
 JFrame frame = new JFrame("FX");
 final JFXPanel fxPanel = new JFXPanel();
 frame.add(fxPanel);
 frame.setBounds(200, 100, 800, 250);
 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
 frame.setVisible(true);

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

public class Expander extends javax.swing.JFrame   
{   
  public Expander()   
  {   
    this.setBounds(0, 0, 300, 300);   
  }   

  public static void main(String args[])   
  {   
    java.awt.EventQueue.invokeLater(new Runnable()   
    {   
      public void run()   
      {   
        new Expander().setVisible(true);   
      }   
    });   
  }   
}

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

import java.awt.*;
import javax.swing.*;

public class MyGui {

  private JFrame window = new JFrame("This is the title");

  public MyGui() {
    initComponents();

    window.setBounds(100, 50, 600, 400); //location, size
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
  }

  public void initComponents() {
    Container cp = window.getContentPane();
    cp.setLayout(new FlowLayout() );
    cp.add(new JLabel("Hello world") );
  }
}

代码示例来源:origin: google/sagetv

static void hideSplash()
{
 synchronized (splashLock)
 {
  if (splashWindow != null)
  {
   splashWindow.setVisible(false);
   splashWindow.removeAll();
   splashWindow.setBounds(0, 0, 0, 0);
   splashWindow.dispose();
   splashWindow = null;
   splashText = null;
  }
 }
}

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

import javax.swing.*;
import java.awt.*;

public class CustomComponent extends JFrame {

private static final long serialVersionUID = 1L;

public CustomComponent() {

}

public static void main(String[] args) {
  JFrame frame = new JFrame("Java Rulez");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setBounds(100,100,600,600);
  frame.getContentPane().setBackground(Color.YELLOW);

  frame.add(new RectangleComponent(0, 0, 500, 500));

  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
}

相关文章

Window类方法