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

How to use
pack
method
in
java.awt.Window

Best Java code snippets using java.awt.Window.pack (Showing top 20 results out of 711)

Refine searchRefine arrow

  • Window.setVisible
  • Container.add
  • JFrame.setDefaultCloseOperation
  • JFrame.<init>
  • Window.setLocationRelativeTo
origin: stackoverflow.com

$cat HelloWorldSwing.java
 package start;
 import javax.swing.*;
 public class HelloWorldSwing {
   public static void main(String[] args) {
     //Create and set up the window.
     JFrame frame = new JFrame("HelloWorldSwing");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     JLabel label = new JLabel("Hello World");
     frame.add(label);
     //Display the window.
     frame.pack();
     frame.setVisible(true);
   }
 }
 class Dummy {
   // just to have another thing to pack in the jar
 }
origin: stackoverflow.com

 import javax.swing.*;

public class BoxLayoutFoo extends JFrame {
  public BoxLayoutFoo() {

   // swap the comments below
   setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); // comment out this line
   //setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS)); // uncomment this line

   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   pack();
   setVisible(true);
  }

  public static void main(String[] args) {
   new BoxLayoutFoo();
  }
}
origin: stackoverflow.com

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

public class YourDialog extends JDialog implements ActionListener {

 JButton button;

 public YourDialog() {
   button = new JButton("Close");
   button.addActionListener(this);
   add(button);
   pack();
   setVisible(true);
 }

 public void actionPerformed(ActionEvent e) {
   dispose();
 }
}
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

 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: stackoverflow.com

 package com.stackoverflow.test;

import java.net.URL;
import javax.swing.*;  // Wild carded for brevity. 
            // Actual code imports single classes
public class Main {
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable(){
      public void run() {
        URL url = Main.class.getResource(
                   "/resources/stackoverflow.png");
        ImageIcon icon = new ImageIcon(url);
        JFrame frame = new JFrame();
        frame.add(new JLabel(icon));
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    });
  }
}
origin: stackoverflow.com

 package temp;
import java.awt.EventQueue;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new NewJPanel());
        f.pack();
        f.setVisible(true);
      }
    });
  }
}
origin: stackoverflow.com

JFrame f = new JFrame("Frame " + ii);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
String s =
  "os.name: " + System.getProperty("os.name") +
  "\nos.version: " + System.getProperty("os.version");
f.add(new JTextArea(s,3,28));  // suggest a size
f.pack();
f.setVisible(true);
origin: stackoverflow.com

JLabel javaHomeLabel = new JLabel("java.home=" + System.getProperty("java.home"));
setLayout(new BorderLayout());
add(versionLabel, BorderLayout.PAGE_START);
add(javaHomeLabel, BorderLayout.PAGE_END);
JFrame frame = new JFrame("MyJavaMacOSXApp");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyJavaMacOSXApp newContentPane = new MyJavaMacOSXApp();
newContentPane.setOpaque(true); 
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
origin: stackoverflow.com

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

public class Main{
  public static void main( String [] args ) throws InterruptedException  {
    JFrame frame = new JFrame();
    frame.add( new JLabel(" Outout" ), BorderLayout.NORTH );

    JTextArea ta = new JTextArea();
    TextAreaOutputStream taos = new TextAreaOutputStream( ta, 60 );
    PrintStream ps = new PrintStream( taos );
    System.setOut( ps );
    System.setErr( ps );


    frame.add( new JScrollPane( ta )  );

    frame.pack();
    frame.setVisible( true );

    for( int i = 0 ; i < 100 ; i++ ) {
      System.out.println( i );
      Thread.sleep( 500 );
    }
  }
}
origin: stackoverflow.com

this.add(combo1);
this.add(combo2);
combo1.addActionListener(this);
JFrame f = new JFrame("ComboTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
origin: stackoverflow.com

JFrame frame = new JFrame();
frame.getContentPane().add(box);
frame.pack();
frame.setVisible(true);
origin: stackoverflow.com

JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea textArea = new JTextArea(24, 80);
textArea.setFont(new Font("monospaced", Font.PLAIN, 12));
frame.add(new JScrollPane(textArea));
frame.pack();
frame.setVisible(true);
origin: stackoverflow.com

+ "The effect we want is a multi-line label.";
JFrame f = new JFrame("Label Render Test");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel imageLabel = new JLabel(ii);
f.getContentPane().add(imageLabel);
f.pack();
f.setLocationByPlatform(true);
f.setVisible(true);
origin: stackoverflow.com

JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new TextOverlay());
f.pack();
f.setVisible(true);
origin: stackoverflow.com

final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
plafComponents.add(plafChooser);
plafComponents.add(pack);
      SwingUtilities.updateComponentTreeUI(frame);
      if (pack.isSelected()) {
        frame.pack();
        frame.setMinimumSize(frame.getSize());
gui.add(plafComponents, BorderLayout.NORTH);
frame.pack();
frame.setLocationRelativeTo(null);
try {
frame.setVisible(true);
origin: stackoverflow.com

 package experiments;

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

public class CreateDialogFromOptionPane {

  public static void main(final String[] args) {
    final JFrame parent = new JFrame();
    JButton button = new JButton();

    button.setText("Click me to show dialog!");
    parent.add(button);
    parent.pack();
    parent.setVisible(true);

    button.addActionListener(new java.awt.event.ActionListener() {
      @Override
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        String name = JOptionPane.showInputDialog(parent,
            "What is your name?", null);
      }
    });
  }
}
origin: stackoverflow.com

for (int r = 0; r < N; r++) {
  for (int c = 0; c < N; c++) {
    this.add(create(r + N, r + 1, c + 2));
JFrame f = new JFrame("HTMLFractions");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
origin: stackoverflow.com

final JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(600, 400));
final JToolBar toolBar = new JToolBar();
toolBar.add(button);
frame.getContentPane().add(toolBar, BorderLayout.NORTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
origin: stackoverflow.com

JFrame f = new JFrame();
setTranslucency( f );
f.setUndecorated( true );
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBackground(new Color(0f, 0f, 0f, 1f / 3f));
f.add(new Translucent());
f.pack();
f.setVisible(true);
java.awtWindowpack

Javadoc

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.

Popular methods of Window

  • dispose
    Releases all of the native screen resources used by thisWindow, its subcomponents, and all of its ow
  • setVisible
  • setLocation
  • 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.
  • getGraphicsConfiguration
    This method returns the GraphicsConfiguration used by this Window.
  • removeWindowListener,
  • getGraphicsConfiguration,
  • isVisible,
  • addComponentListener,
  • getX,
  • getY,
  • toFront,
  • getLocation,
  • removeComponentListener

Popular in Java

  • Making http post requests using okhttp
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSupportFragmentManager (FragmentActivity)
  • getApplicationContext (Context)
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Top PhpStorm plugins
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