Tabnine Logo
Window
Code IndexAdd Tabnine to your IDE (free)

How to use
Window
in
java.awt

Best Java code snippets using java.awt.Window (Showing top 20 results out of 3,096)

Refine searchRefine arrow

  • Container
  • JFrame
  • JComponent
  • Component
  • JPanel
  • JButton
origin: stackoverflow.com

JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog"));
JPanel panel = new JPanel();
panel.add(showWaitBtn);
JFrame frame = new JFrame("Frame");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
   if (evt.getPropertyName().equals("state")) {
     if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
      dialog.dispose();
JPanel panel = new JPanel(new BorderLayout());
panel.add(progressBar, BorderLayout.CENTER);
panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START);
dialog.add(panel);
dialog.pack();
dialog.setLocationRelativeTo(win);
dialog.setVisible(true);
origin: stackoverflow.com

final JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel l = new JLabel();
new Thread(t).start();
final JButton b = new JButton("Stop");
b.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e)
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add(l, BorderLayout.CENTER);
f.getContentPane().add(b, BorderLayout.SOUTH);
f.setLocation(100, 100);
f.pack();
f.setVisible(true);
origin: stackoverflow.com

go = new JButton("Do it");
go.addActionListener(this);
add(go);
JFrame frame = new JFrame("");
DemoJFileChooser panel = new DemoJFileChooser();
frame.addWindowListener(
 new WindowAdapter() {
  public void windowClosing(WindowEvent e) {
frame.getContentPane().add(panel,"Center");
frame.setSize(panel.getPreferredSize());
frame.setVisible(true);
origin: log4j/log4j

protected void centerWindow(Window win) {
 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
 // If larger than screen, reduce window width or height
 if (screenDim.width < win.getSize().width) {
  win.setSize(screenDim.width, win.getSize().height);
 }
 if (screenDim.height < win.getSize().height) {
  win.setSize(win.getSize().width, screenDim.height);
 }
 // Center Frame, Dialogue or Window on screen
 int x = (screenDim.width - win.getSize().width) / 2;
 int y = (screenDim.height - win.getSize().height) / 2;
 win.setLocation(x, y);
}
origin: stackoverflow.com

 import javax.swing.JFrame;
import javax.swing.JLabel;

public class Annoying {
  public static void main(String[] args) {
    JFrame frame = new JFrame("Hello!!");

    // Set's the window to be "always on top"
    frame.setAlwaysOnTop( true );

    frame.setLocationByPlatform( true );
    frame.add( new JLabel("  Isn't this annoying?") );
    frame.pack();
    frame.setVisible( true );
  }
}
origin: skylot/jadx

public void saveWindowPos(Window window) {
  WindowLocation pos = new WindowLocation(window.getClass().getSimpleName(),
      window.getX(), window.getY(),
      window.getWidth(), window.getHeight()
  );
  windowPos.put(pos.getWindowId(), pos);
  partialSync(settings -> settings.windowPos = windowPos);
}
origin: stackoverflow.com

 import javax.swing.JFrame;
import javax.swing.JLabel;

public class AnotherJFrame extends JFrame
{
  public AnotherJFrame()
  {
    super("Another GUI");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    add(new JLabel("Empty JFrame"));
    pack();
    setVisible(true);
  }
}
origin: stackoverflow.com

plafComponents.add(plafChooser);
plafComponents.add(pack);
      SwingUtilities.updateComponentTreeUI(frame);
      if (pack.isSelected()) {
        frame.pack();
        frame.setMinimumSize(frame.getSize());
gui.add(plafComponents, BorderLayout.NORTH);
  new TitledBorder("GridLayout(0,2,3,3)") );
JButton addNew = new JButton("Add Another Label");
frame.setContentPane(gui);
frame.pack();
frame.setLocationRelativeTo(null);
try {
  frame.setLocationByPlatform(true);
  frame.setMinimumSize(frame.getSize());
} catch(Throwable ignoreAndContinue) {
frame.setVisible(true);
origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setTitle("Welcome!");
frame.setSize(520, 480);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel heroShotPanel = new JPanel();
JLabel heroShot = new JLabel(heroShotImage);
heroShotPanel.add(heroShot);
JPanel submitPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton start = new JButton("Start");
start.setToolTipText("Click to use library");
submitPanel.add(start);
frame.getContentPane().add(heroShotPanel, BorderLayout.NORTH);
frame.getContentPane().add(submitPanel, BorderLayout.SOUTH);
frame.setVisible(true);
frame.getRootPane().setDefaultButton(start);
start.requestFocus();
origin: stackoverflow.com

      JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  JPanel bottomPanel = CreateBottomPanel();
  frame = new JFrame("Comp Table Test");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(CompTableScrollpane, BorderLayout.CENTER);
  frame.add(bottomPanel, BorderLayout.SOUTH);
  frame.setPreferredSize(new Dimension(800, 400));
  frame.setLocation(150, 150);
  frame.pack();
  frame.setVisible(true);
  addButton = new JButton("Add Comp");
  addButton.addActionListener(new ActionListener() {
  JPanel panel = new JPanel(new GridBagLayout());
  panel.add(addButton);
  return panel;
private JLabel labelAnd = new JLabel(" and ");
private JTextField upperField = new JTextField();
private JButton removeButton = new JButton("remove");
  labelAnd.setEnabled(enable);
  upperField.setEnabled(enable);
origin: stackoverflow.com

repaint();
repaint();
JFrame testFrame = new JFrame();
testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
final LinesComponent comp = new LinesComponent();
comp.setPreferredSize(new Dimension(320, 200));
testFrame.getContentPane().add(comp, BorderLayout.CENTER);
JPanel buttonsPanel = new JPanel();
JButton newLineButton = new JButton("New Line");
JButton clearButton = new JButton("Clear");
buttonsPanel.add(newLineButton);
buttonsPanel.add(clearButton);
testFrame.getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
newLineButton.addActionListener(new ActionListener() {
testFrame.pack();
testFrame.setVisible(true);
origin: stackoverflow.com

 component.getWidth(),
 component.getHeight(),
 BufferedImage.TYPE_INT_RGB
 );
component.paint( image.getGraphics() ); // alternately use .printAll(..)
return image;
Runnable r = new Runnable() {
 public void run() {
  final JFrame f = new JFrame("Test Screenshot");
    public void actionPerformed(ActionEvent ae) {
     BufferedImage img = getScreenShot(
      f.getContentPane() );
     JOptionPane.showMessageDialog(
      null,
  JMenuBar mb = new JMenuBar();
  mb.add(menu);
  f.setJMenuBar(mb);
  f.setContentPane( p );
  f.pack();
  f.setLocationRelativeTo(null);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setVisible(true);
origin: stackoverflow.com

setLayout(new BorderLayout());
this.panel = new JPanel();
this.panel.setLayout(new FlowLayout());
add(panel, BorderLayout.CENTER);
JButton button = new JButton("CLICK HERE");
add(button, BorderLayout.SOUTH);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setVisible(true);
this.panel.add(new JButton("Button"));
this.panel.revalidate();
validate();
origin: stackoverflow.com

JFrame frame = new JFrame("DialogClosing");
JPanel mainPanel = new JPanel();
mainPanel.add(new JButton(new MyAction(frame, JDialog.DISPOSE_ON_CLOSE, "DISPOSE_ON_CLOSE")));
mainPanel.add(new JButton(new MyAction(frame, JDialog.HIDE_ON_CLOSE, "HIDE_ON_CLOSE")));
mainPanel.add(new JButton(new MyAction(frame, JDialog.DO_NOTHING_ON_CLOSE, "DO_NOTHING_ON_CLOSE")));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
dialog = new JDialog(frame, title, false);
dialog.setDefaultCloseOperation(defaultCloseOp);
dialog.setPreferredSize(new Dimension(300, 200));
dialog.pack();
dialog.addWindowListener(new WindowAdapter() {
  @Override
  public void windowClosed(WindowEvent e) {
origin: stackoverflow.com

private JPanel panel = new JPanel();
private JScrollPane sp = new JScrollPane(panel);
  panel.add(new JLabel(name, JLabel.LEFT));
  panel.add(jtf);
  list.add(jtf);
  panel.setLayout(new GridLayout(0, 1));
  addField("First Name:");
  addField("Last Name:");
  internaFrame.add(sp);
  internaFrame.pack();
  internaFrame.setVisible(true);
  desktopPane.add(internaFrame);
  JFrame frmtest = new JFrame();
  frmtest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frmtest.add(desktopPane);
  frmtest.pack();
  frmtest.setSize(400, 300);
  frmtest.setLocationRelativeTo(null);
  frmtest.setVisible(true);
  list.get(0).requestFocusInWindow();
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

 @Override
 public void run() {
  JFrame testFrame = new JFrame( "FormattedTextFieldDemo" );
  integerFormattedTextField.setColumns( 20 );
  testFrame.add( createButtonPanel( integerFormattedTextField ), BorderLayout.NORTH );
  integerFormattedTextField.addPropertyChangeListener( "value", updateTextAreaListener );
  testFrame.add( new JScrollPane( textArea ), BorderLayout.CENTER );
  testFrame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
  testFrame.pack();
  testFrame.setVisible( true );
JPanel panel = new JPanel( new BorderLayout(  ) );
panel.add( aTextField, BorderLayout.WEST );
panel.add( new JButton( action ), BorderLayout.EAST );
return panel;
origin: stackoverflow.com

  JFrame f = new JFrame();
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.add(new MainPanel());
  f.pack();
  f.setLocationRelativeTo(null);
  f.setVisible(true);
  Control control = new Control(model, view);
  JLabel label = new JLabel("Guess what color!", JLabel.CENTER);
  this.add(label, BorderLayout.NORTH);
  this.add(view, BorderLayout.CENTER);
  this.add(control, BorderLayout.SOUTH);
private JButton reset = new JButton("Reset");
  JPanel panel = new JPanel();
  for (Piece p : Piece.values()) {
    PieceButton pb = new PieceButton(p);
    PieceButton pb = (PieceButton) e.getSource();
    icon.color = pb.piece.color;
    label.repaint();
    model.check(pb.piece);
origin: stackoverflow.com

l.setBorder(new LineBorder(Color.RED, 2));
return l;
SwingUtilities.invokeLater(new Runnable() {
  public void run() {
    JPanel p = new JPanel(new GridLayout(2,2,4,4));
    p.setBackground(Color.black);
    p.setBorder(new EmptyBorder(4,4,4,4));
    JPanel border = new JPanel(new BorderLayout());
    border.add(getLabel(
      "Border", SwingConstants.CENTER), BorderLayout.CENTER);
    p.add(border);
    JPanel gridbag = new JPanel(new GridBagLayout());
    gridbag.add(getLabel("GridBag"));
    p.add(gridbag);
    p.add(box);
    JFrame f = new JFrame("Streeeetch me..");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);
origin: stackoverflow.com

setLayout(new BorderLayout());
JPanel jp = new JPanel();
jp.setLayout(new BorderLayout());
JTabbedPane tb = new JTabbedPane();
tb.setUI(new CustomTabbedPaneUI());
tb.add("Tab4", new JTextArea(""));
tb.add("Tab5", new JTextArea(""));
jp.add(tb, BorderLayout.CENTER);
add(jp, BorderLayout.CENTER);
tb.setEnabledAt(1, false);
JFrame frame = new JFrame();
frame.getContentPane().add(new TabbedPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 200);
frame.setVisible(true);
java.awtWindow

Javadoc

A Window object is a top-level window with no borders and no menubar. The default layout for a window is BorderLayout. Note: the location and size of top-level windows (including Windows, Frames, and Dialogs) are under the control of the window management system. Calls to setLocation, setSize, and setBounds are requests (not directives) which are forwarded to the window management system. In some cases the window management system may ignore such requests, or modify the requested geometry in order to place and size the Window appropriately. Due to the asynchronous nature of native event handling, the results returned by getBounds, getLocation, getLocationOnScreen, and getSize might not reflect the actual geometry of the Window on screen until the last request has been processed. During the processing of subsequent requests these values might change accordingly while the window management system fulfills the requests.

An application may set the size and location of an invisible Window arbitrarily, but the window management system may subsequently change its size and/or location if and when the Window is made visible. One or more ComponentEvents will be generated to indicate the new geometry.

Windows are capable of generating the following WindowEvents: WindowOpened, WindowClosed, WindowGainedFocus, WindowLostFocus.

Most used methods

  • dispose
    Releases all of the native screen resources used by thisWindow, its subcomponents, and all of its ow
  • setVisible
  • setLocation
  • pack
    Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the wi
  • addWindowListener
    Adds the specified window listener to receive window events from this window. If l is null, no excep
  • getSize
  • getWidth
  • getHeight
  • setSize
  • setBounds
  • getBounds
  • removeWindowListener
    Removes the specified window listener so that it no longer receives window events from this window.
  • getBounds,
  • removeWindowListener,
  • getGraphicsConfiguration,
  • isVisible,
  • addComponentListener,
  • getX,
  • getY,
  • toFront,
  • getLocation,
  • removeComponentListener

Popular in Java

  • Start an intent from android
  • requestLocationUpdates (LocationManager)
  • notifyDataSetChanged (ArrayAdapter)
  • getApplicationContext (Context)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JTextField (javax.swing)
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now