About 71,400 results
Open links in new tab
  1. How to place an object in a specific location (x,y) on a JFrame?

    Jun 9, 2012 · Here find the Absolute Positioning Tutorials. Please do read carefully, as to why this approach is discouraged over using LayoutManagers. To add say a JButton to your JPanel, you can use this : Here try this example program : import javax.swing.*; private void displayGUI() JFrame frame = new JFrame("Absolute Layout Example");

  2. java - How to set position of objects in JFrame? - Stack Overflow

    How to manage the object's position in JFrame? See Lesson: Laying Out Components Within a Container. Use proper LayoutManager. E.g. GridBagLayout. Or you can combine multiple nested panels assigning own LayoutManager for each panel. The worst way is to set layout to null and use setBounds() Agree, setLayout null is a bad way to do it!

  3. How to change the position of label in frame using java

    Jan 22, 2015 · It is fairly easy to change the position of your JLabel instance by using two methods which are really handing. Look below for the code to use : HelloWorldFrame() { JLabel jlb=new JLabel("HelloWorld"); jlb.setHorizontalAlignment(50); // set the horizontal alignement on …

  4. How to Change the Position of JButton in Java - StackHowTo

    Aug 11, 2021 · setBounds () method is used to set the position and size. To manually specify the position and size of the components, the layout manager of the frame can be null. setBounds () method needs four arguments.

  5. Set Location of JLabel in a JFrame with Java - Online Tutorials …

    To set location of a component in a JFrame, use the setBounds () method. Let us first create a frame and a panel −. Create a component i.e. label and set the dimensions using setBounds (). Here, you can set the location in the form of x and y coordinates −. JLabel label = new JLabel("Demo Label!");

  6. How to Set JFrame in Center of the Screen - StackHowTo

    Aug 22, 2021 · To change the position of JFrame on the screen, JFrame provides the method JFrame.setlocation (int x, int y), you need two parameters ‘x’ represents the position of the x axis and ‘y’ represents the position of the y axis. The upper left corner of your screen is (0,0).

  7. Resize and Position a JFrame in Java - Online Tutorials Library

    To resize and position JFrame, use the Dimensions class. Here, we have set the bounds for the frame − int width = 500; int height = 400; Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); frame.setBounds((int) size.getWidth() - width, …

  8. Using an Object - Princeton University

    First, let's focus on how to inspect and modify the Rectangle's position by modifying its x and y variables. The next section will show you how to move the rectangle by calling its move() method. To reference an object's variables, simply append the variable name to an object reference with an intervening '.' (period). objectReference.variable

  9. java - How to place components at specific positions ... - Stack Overflow

    Apr 4, 2017 · Try to change the layout. http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html. You could go for a GridLayout with two lines (for example, there is some others possible combinations), with each line containing respectively 3 JComboBoxs, and two JTextFields.

  10. java - Setting the positions of nodes based on a layout - Code

    Feb 29, 2016 · For example, an easy fix would be to create a Position(double x, double y) constructor, and do the double -> Double -> int conversion in the constructor. this.x = new Double(x).intValue(); . this.y = new Double(y).intValue(); . This would change the code to: for (Node n : g.getNodes().values()){

  11. Some results have been removed