Tabnine Logo
Component.getSize
Code IndexAdd Tabnine to your IDE (free)

How to use
getSize
method
in
java.awt.Component

Best Java code snippets using java.awt.Component.getSize (Showing top 20 results out of 2,556)

Refine searchRefine arrow

  • Window.setVisible
  • JFrame.setDefaultCloseOperation
  • Container.add
  • JFrame.<init>
  • Window.pack
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.setMinimumSize(frame.getSize());
} catch(Throwable ignoreAndContinue) {
frame.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

JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new TestPane());
BORDER_CACHE.put(c, new CachedBorder(dropShadow, c.getSize()));
if (comp.getSize().equals(size)) {
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

basePanel.setSize(parent.getSize());
basePanel.setLayout(new BorderLayout());
if (useSlideButton) {
  final JPanel statusPanel = new JPanel();
  basePanel.add(statusPanel, BorderLayout.SOUTH);
  statusPanel.add(new JButton("Slide Left") {
    private static final long serialVersionUID = 9204819004142223529L;
  statusPanel.add(new JButton("Slide Right") {
    basePanel.add(component);
  component.setSize(basePanel.getSize());
  component.setLocation(0, 0);
origin: net.sf.tinylaf/tinylaf

public void setupUI(Frame frame) {
  JScrollPane sp = new JScrollPane(editor);
  getContentPane().add(sp);
  
  pack();
  
  setSize(800, 600);
  setLocation(frame.getLocationOnScreen().x + 
    (frame.getWidth() - getSize().width) / 2,
    frame.getLocationOnScreen().y + 
    (frame.getHeight() - getSize().height) / 2);
}
origin: nroduit/Weasis

public static void showCenterScreen(Window window, Component parent) {
  if (parent == null) {
    showCenterScreen(window);
  } else {
    Dimension sSize = parent.getSize();
    Dimension wSize = window.getSize();
    Point p = parent.getLocationOnScreen();
    window.setLocation(p.x + ((sSize.width - wSize.width) / 2), p.y + ((sSize.height - wSize.height) / 2));
    window.setVisible(true);
  }
}
origin: stackoverflow.com

private JFrame frame = new JFrame("sssssssss");
private JButton tip1Null = new JButton(" test button ");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(tip1Null, BorderLayout.CENTER);
  frame.setLocation(150, 150);
  frame.setPreferredSize(new Dimension(310, 75));
  frame.setLocationRelativeTo(null);
  frame.pack();
  frame.setVisible(true);
  paintText(g, b, b.getBounds(), b.getText());
  g.setColor(Color.red.brighter());
  g.fillRect(0, 0, b.getSize().width, b.getSize().height);
origin: stackoverflow.com

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

public class FrameInfo
{
  public static void main(String[] args)
  {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = env.getMaximumWindowBounds();
    System.out.println("Screen Bounds: " + bounds );

    GraphicsDevice screen = env.getDefaultScreenDevice();
    GraphicsConfiguration config = screen.getDefaultConfiguration();
    System.out.println("Screen Size  : " + config.getBounds());

    JFrame frame = new JFrame("Frame Info");
    System.out.println("Frame Insets : " + frame.getInsets() );

    frame.setSize(200, 200);
    System.out.println("Frame Insets : " + frame.getInsets() );
    frame.setVisible( true );

    System.out.println("Frame Size   : " + frame.getSize() );
    System.out.println("Frame Insets : " + frame.getInsets() );
    System.out.println("Content Size : " + frame.getContentPane().getSize() );
   }
}
origin: net.sf.jt400/jt400

    /**
     * Creates the pane.
    **/
    private void createPane()
    {
      // This is for the OK, Cancel, and Apply buttons
      JPanel buttonPanel = getButtonPanel();

      // This is for the rest
      JPanel panel = getModifyTab();

      Container container = getContentPane();
      container.setLayout(new BorderLayout());

      JTabbedPane tabbedPane = new JTabbedPane();
      tabbedPane.addTab(modifyActionTab_, panel);
//            container.add("West", new JPanel());
//            container.add("East", new JPanel());
      container.add("South", buttonPanel);        
      container.add("Center", tabbedPane);  
      setLocation(parent_.getLocation().x+parent_.getSize().width/2,
          parent_.getLocation().y+parent_.getSize().height/2);
      list_.setSelectedIndex(0);
      textField_.setText((String)list_.getSelectedValue());
    }

origin: stackoverflow.com

JFrame frame = new JFrame();
frame.setSize(460, 500);
frame.setTitle("Circles generator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
frame.add(component);
frame.getContentPane().validate();
frame.getContentPane().repaint();
public void paintComponent(Graphics g) {
  int margin = 10;
  Dimension dim = getSize();
  super.paintComponent(g);
  g.setColor(Color.red);
origin: stackoverflow.com

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

public class FrameInfo
{
  public static void main(String[] args)
  {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = env.getMaximumWindowBounds();
    System.out.println("Screen Bounds: " + bounds );

    GraphicsDevice screen = env.getDefaultScreenDevice();
    GraphicsConfiguration config = screen.getDefaultConfiguration();
    System.out.println("Screen Size  : " + config.getBounds());
    System.out.println(Toolkit.getDefaultToolkit().getScreenSize());

    JFrame frame = new JFrame("Frame Info");
    frame.setSize(200, 200);
    frame.setVisible( true );

    System.out.println("Frame Size   : " + frame.getSize() );
    System.out.println("Frame Insets : " + frame.getInsets() );
    System.out.println("Content Size : " + frame.getContentPane().getSize() );
   }
}
origin: stackoverflow.com

 public void actionPerformed(ActionEvent e) {
  HistoryLogPane.setLayout(new ScrollPaneLayout());//<<<
  history = (JPanel)HistoryLogPane.getViewport().getView();//<<<
  javax.swing.JScrollPane HistoryLogPane = new javax.swing.JScrollPane();
  HistoryLogPane.setLayout(new ScrollPaneLayout()); // edit @kiheru
  HistoryLogPane.setBackground(Color.WHITE);
  HistoryLogPane.setBorder(BorderFactory.createEmptyBorder());
  HistoryLogPane.setLocation(0, 0);
  HistoryLogPane.add(history);
  HistoryLogPane.setSize(new Dimension(history.getSize()));
  history.setPreferredSize(history.getSize());//and we tried: history.setPreferredSize(history.getPreferredSize());
  history.revalidate();//<<<
  System.out.println("SIZE: " + HistoryLogPane.getSize());
  HistoryLocationPanel.removeAll();
  HistoryLocationPanel.add(HistoryLogPane);
  HistoryLocationPanel.repaint();
  HistoryLogPane.repaint();
}
origin: stackoverflow.com

JToolBar tools = new JToolBar();
tools.setFloatable(false);
gui.add(tools, BorderLayout.PAGE_START);
tools.add(new JButton("New")); // TODO - add functionality!
tools.add(new JButton("Save")); // TODO - add functionality!
tools.add(new JButton("Restore")); // TODO - add functionality!
tools.addSeparator();
        new ChessBoardWithColumnsAndRows();
    JFrame f = new JFrame("ChessChamp");
    f.add(cb.getGui());
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setLocationByPlatform(true);
    f.pack();
    f.setMinimumSize(f.getSize());
    f.setVisible(true);
origin: stackoverflow.com

System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
JFrame frame = new JFrame("Frame Info");
frame.setVisible( true );
System.out.println("Frame Size   : " + frame.getSize() );
System.out.println("Frame Insets : " + frame.getInsets() );
System.out.println("Content Size : " + frame.getContentPane().getSize() );
origin: stackoverflow.com

    public void componentResized(ComponentEvent e) {
      JButton btn = (JButton) e.getComponent();
      Dimension size = btn.getSize();
      Insets insets = btn.getInsets();
      size.width -= insets.left + insets.right;
  JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(btn);
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
} catch (IOException exp) {
  exp.printStackTrace();
origin: stackoverflow.com

    background.setBackground(ImageIO.read(new File("/path/to/your/image/on/your/disk")));
    JFrame frame = new JFrame("Testing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(background);
    frame.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    frame.add(new JLabel("Hello world"), gbc);
    frame.add(new JLabel("I'm on top"), gbc);
    frame.add(new JButton("Clickity-clackity"), gbc);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  } catch (IOException exp) {
    exp.printStackTrace();
super.invalidate();
if (getWidth() > img.getWidth() || getHeight() > img.getHeight()) {
  scaled = getScaledInstanceToFill(img, getSize());
} else {
  scaled = img;
origin: stackoverflow.com

 g.setColor(getBackground());
g.fillOval(0, 0, getSize().width-1, 
 getSize().height-1);
g.drawOval(0, 0, getSize().width-1, 
 getSize().height-1);
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.yellow);
frame.getContentPane().add(button);
frame.getContentPane().setLayout(new FlowLayout());
frame.setSize(150, 150);
frame.setVisible(true);
origin: stackoverflow.com

Floor2 mainPanel = new Floor2(w, h, gridDiv);
JFrame frame = new JFrame("Floor2");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
for (int i = 1; i < grid; i++) {
  int x = i * divisionSize;
  g2.drawLine(x, 0, x, getSize().height);
  g2.drawLine(0, y, getSize().width, y);
origin: stackoverflow.com

ui.add(text, BorderLayout.PAGE_START);
io = new JTextField(15);
Font font = io.getFont();
io.setHorizontalAlignment(SwingConstants.TRAILING);
io.setFocusable(false);
text.add(io);
ui.add(buttons, BorderLayout.CENTER);
String[] keyValues = {
  "7", "8", "9", "/",
  public void run() {
    ScriptEngineCalculator sc = new ScriptEngineCalculator();
    JFrame f = new JFrame("Calculet");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    f.setContentPane(sc.getUI());
    f.pack();
    f.setMinimumSize(f.getSize());
    f.setLocationByPlatform(true);
    f.setVisible(true);
java.awtComponentgetSize

Javadoc

Returns the size of this component in the form of a Dimension object. The height field of the Dimension object contains this component's height, and the width field of the Dimension object contains this component's width.

Popular methods of Component

  • getParent
    Gets the parent of this component.
  • getPreferredSize
    Gets the preferred size of this component.
  • getHeight
    Returns the current height of this component. This method is preferable to writingcomponent.getBound
  • getWidth
    Returns the current width of this component. This method is preferable to writingcomponent.getBounds
  • isVisible
    Determines whether this component should be visible when its parent is visible. Components are initi
  • setBounds
    Moves and resizes this component to conform to the new bounding rectangle r. This component's new po
  • getName
    Gets the name of the component.
  • setEnabled
    Enables or disables this component, depending on the value of the parameter b. An enabled component
  • setBackground
    Sets the background color of this component. The background color affects each component differently
  • setVisible
    Shows or hides this component depending on the value of parameterb.
  • getMinimumSize
    Gets the mininimum size of this component.
  • getBackground
    Gets the background color of this component.
  • getMinimumSize,
  • getBackground,
  • addMouseListener,
  • getBounds,
  • setForeground,
  • repaint,
  • setCursor,
  • setSize,
  • requestFocus

Popular in Java

  • Running tasks concurrently on multiple threads
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • compareTo (BigDecimal)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • 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