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

How to use
JFrame
in
javax.swing

Best Java code snippets using javax.swing.JFrame (Showing top 20 results out of 9,468)

Refine searchRefine arrow

  • Window
  • Container
  • JComponent
  • Component
  • JPanel
  • JButton
origin: libgdx/libgdx

  public void run () {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(480, 320);
    frame.setLocationRelativeTo(null);
    JPanel panel = new JPanel();
    frame.getContentPane().add(panel);
    panel.add(new NewSlider(200, 100, 500, 0.1f, 150, 300));
    frame.setVisible(true);
  }
});
origin: spotbugs/spotbugs

  public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setTitle("Title");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton();
    button.setText("Hello, World!");
    frame.getContentPane().add(button, BorderLayout.CENTER);
    frame.setSize(200, 100);
    frame.pack();
    frame.setVisible(true);
    frame.show();
  }
}
origin: stackoverflow.com

 JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(200, 200);

// create the status bar panel and shove it down the bottom of the frame
JPanel statusPanel = new JPanel();
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
frame.add(statusPanel, BorderLayout.SOUTH);
statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
JLabel statusLabel = new JLabel("status");
statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
statusPanel.add(statusLabel);

frame.setVisible(true);
origin: stackoverflow.com

JFrame frame = new JFrame("FooRendererTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel); // or whatever...
frame.pack();
frame.setLocationRelativeTo(null);  // *** this will center your app ***
frame.setVisible(true);
origin: knowm/XChange

 @Override
 public void run() {
  // Create and set up the window.
  JFrame frame = new JFrame("XChart");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(chartPanel);
  // Display the window.
  frame.pack();
  frame.setVisible(true);
 }
});
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: apache/shiro

updateValueLabel();
saveButton = new JButton("Save Value");
saveButton.addActionListener(this);
refreshButton = new JButton("Refresh Value");
refreshButton.addActionListener(this);
JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
valuePanel.add(valueField);
valuePanel.add(saveButton);
valuePanel.add(refreshButton);
methodPanel.add(secureMethod3Button);
frame = new JFrame("Apache Shiro Sample Application");
frame.setSize(500, 200);
Container panel = frame.getContentPane();
panel.setLayout(new BorderLayout());
panel.add(logo, BorderLayout.NORTH);
panel.add(valuePanel, BorderLayout.CENTER);
panel.add(methodPanel, BorderLayout.SOUTH);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent e) {
    System.exit(0);
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: stanfordnlp/CoreNLP

private void buildExtractButton() {
 if (extractButton == null) {
  JPanel buttonPanel = new JPanel();
  extractButton = new JButton("Run NER");
  buttonPanel.add(extractButton);
  frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
  extractButton.addActionListener(actor);
 }
}
origin: stackoverflow.com

 public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.setLayout(new GridBagLayout());
  JPanel panel = new JPanel();
  panel.add(new JLabel("This is a label"));
  panel.setBorder(new LineBorder(Color.BLACK)); // make it easy to see
  frame.add(panel, new GridBagConstraints());
  frame.setSize(400, 400);
  frame.setLocationRelativeTo(null);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);
}
origin: stanfordnlp/CoreNLP

private void buildExtractButton() {
 if (extractButton == null) {
  JPanel buttonPanel = new JPanel();
  extractButton = new JButton("Extract");
  buttonPanel.add(extractButton);
  frame.add(buttonPanel, BorderLayout.SOUTH);
  extractButton.addActionListener(actor);
 }
}
origin: stackoverflow.com

final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel gui = new JPanel(new BorderLayout(5,5));
gui.setBorder( new TitledBorder("BorderLayout(5,5)") );
plafComponents.add(plafChooser);
plafComponents.add(pack);
gui.add(plafComponents, BorderLayout.NORTH);
  new TitledBorder("GridLayout(0,2,3,3)") );
JButton addNew = new JButton("Add Another Label");
dynamicLabels.add( addNew, BorderLayout.NORTH );
addNew.addActionListener( new ActionListener(){
gui.add( splitPane, BorderLayout.CENTER );
frame.setContentPane(gui);
frame.pack();
frame.setLocationRelativeTo(null);
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

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: jMonkeyEngine/jmonkeyengine

private static void createWindowForPanel(AwtPanel panel, int location){
  JFrame frame = new JFrame("Render Display " + location);
  frame.getContentPane().setLayout(new BorderLayout());
  frame.getContentPane().add(panel, BorderLayout.CENTER);
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosed(WindowEvent e) {
      if (++panelsClosed == 2){
        app.stop();
      }
    }
  });
  frame.pack();
  frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
  frame.setVisible(true);
}

origin: jMonkeyEngine/jmonkeyengine

  public void run(){
    JFrame frame = new JFrame("Render Display");
    display = new ImageDisplay();
    display.setPreferredSize(new Dimension(width, height));
    frame.getContentPane().add(display);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter(){
      public void windowClosed(WindowEvent e){
        stop();
      }
    });
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setVisible(true);
  }
});
origin: 4thline/cling

protected MediaRendererController() {
  super(new JFrame(MediaRenderer.APPNAME), new MediaRendererLogCategories());
  statusIconButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
      toggleLogPanel();
  statusIconButton.setFocusable(false);
  statusIconPanel.setPreferredSize(new Dimension(150, 200));
  statusIconPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
  statusIconPanel.add(statusIconButton);
  getLogPanel().setPreferredSize(new Dimension(800, 175));
  getView().setMinimumSize(new Dimension(150, 200));
  getView().add(statusIconPanel, BorderLayout.WEST);
  getView().add(getLogPanel(), BorderLayout.CENTER);
  getView().addWindowListener(this);
  getView().pack();
  getView().setResizable(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

 private void makeGUI()
{
  final JFrame f = new JFrame();
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.getContentPane().setLayout(new FlowLayout());

  // include: "class AnswerWorker" code here.
  // include: "JButton" b code here.

  f.getContentPane().add(b);
  f.getContentPane().add(new JButton("Nothing"));
  f.pack();
  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();
javax.swingJFrame

Most used methods

  • <init>
  • setVisible
  • setDefaultCloseOperation
  • pack
  • getContentPane
  • setSize
  • add
  • addWindowListener
  • dispose
  • setTitle
  • setContentPane
  • setLocation
  • setContentPane,
  • setLocation,
  • setLocationRelativeTo,
  • setJMenuBar,
  • setLayout,
  • setResizable,
  • setIconImage,
  • setBounds,
  • getRootPane,
  • getSize

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSupportFragmentManager (FragmentActivity)
  • getApplicationContext (Context)
  • getExternalFilesDir (Context)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Collectors (java.util.stream)
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Top Sublime Text 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