Java Code Examples for java.awt.Container#getHeight()

The following examples show how to use java.awt.Container#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LineLayout.java    From oim-fx with MIT License 10 votes vote down vote up
private void layoutContainerH(Container target) {
    int maxHeight = 0;
    Dimension size;
    int height;
    Insets insets = target.getInsets();

    for (Component component : target.getComponents()) {
        if (component.isVisible()) {
            size = component.getPreferredSize();

            if (fillComponents.contains(component)) {
                height = target.getHeight() - insets.top - insets.bottom - topGap - bottomGap;
            } else {
                height = size.height;

                if (height > maxHeight) {
                    maxHeight = height;
                }
            }

            component.setSize(size.width, height);
        }
    }

    moveComponentsH(target, maxHeight);
}
 
Example 2
Source File: SeaGlassDesktopPaneUI.java    From seaglass with Apache License 2.0 8 votes vote down vote up
public void deiconifyFrame(JInternalFrame f) {
    JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
    Container c = desktopIcon.getParent();
    if (c != null) {
        c = c.getParent();
        if (c != null) {
            c.add(f);
            if (f.isMaximum()) {
                int w = c.getWidth();
                int h = c.getHeight() - taskBar.getHeight();
                if (f.getWidth() != w || f.getHeight() != h) {
                    setBoundsForFrame(f, 0, 0, w, h);
                }
            }
            if (f.isSelected()) {
                f.moveToFront();
            } else {
                try {
                    f.setSelected(true);
                } catch (PropertyVetoException e2) {
                }
            }
        }
    }
}
 
Example 3
Source File: GroupLayout.java    From openjdk-8-source with GNU General Public License v2.0 8 votes vote down vote up
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 4
Source File: GroupLayout.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 5
Source File: GroupLayout.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 6
Source File: HorizontalSplitPane.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void layoutContainer(Container parent) {
	Insets in = parent.getInsets();
	int maxWidth = parent.getWidth() - (in.left + in.right);
	int maxHeight = parent.getHeight() - (in.top + in.bottom);
	int split;
	if (fraction <= 0.0) {
		split = 0;
	} else if (fraction >= 1.0) {
		split = maxWidth;
	} else {
		split = (int) Math.round(maxHeight * fraction);
		split = Math.min(split, maxHeight - comp1.getMinimumSize().height);
		split = Math.max(split, comp0.getMinimumSize().height);
	}

	comp0.setBounds(in.left, in.top, maxWidth, split);
	comp1.setBounds(in.left, in.top + split, maxWidth, maxHeight - split);
	dragbar.setBounds(in.left, in.top + split - DRAG_TOLERANCE, maxWidth, 2 * DRAG_TOLERANCE);
}
 
Example 7
Source File: GroupLayout.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Lays out the specified container.
 *
 * @param parent the container to be laid out
 * @throws IllegalStateException if any of the components added to
 *         this layout are not in both a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 8
Source File: VerticalGridLayout.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void layoutContainer(Container parent) {
    int x = 0;
    int y = 0;
    int cellWidth = getMaxCellWidth();
    for (Component c : this.components) {
        if (c.isVisible()) {
            Dimension d = c.getPreferredSize();
            if (y + d.height > parent.getHeight()) {
                x += cellWidth;
                y = 0;
            }
            c.setBounds(x + 1, y + 1, cellWidth, d.height);
            y += d.height;
        }
    }
}
 
Example 9
Source File: GroupLayout.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
/**
 * Lays out the specified container.
 * 
 * @param parent
 *            the container to be laid out
 * @throws IllegalStateException
 *             if any of the components added to this layout are not in both
 *             a horizontal and vertical group
 */
public void layoutContainer(Container parent) {
	// Step 1: Prepare for layout.
	prepare(SPECIFIC_SIZE);
	Insets insets = parent.getInsets();
	int width = parent.getWidth() - insets.left - insets.right;
	int height = parent.getHeight() - insets.top - insets.bottom;
	boolean ltr = isLeftToRight();
	if (getAutocreateGaps() || getAutocreateContainerGaps() || hasPreferredPaddingSprings) {
		// Step 2: Calculate autopadding springs
		calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0, width);
		calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0, height);
	}
	// Step 3: set the size of the groups.
	horizontalGroup.setSize(HORIZONTAL, 0, width);
	verticalGroup.setSize(VERTICAL, 0, height);
	// Step 4: apply the size to the components.
	Iterator componentInfo = componentInfos.values().iterator();
	while (componentInfo.hasNext()) {
		ComponentInfo info = (ComponentInfo) componentInfo.next();
		Component c = info.getComponent();
		info.setBounds(insets, width, ltr);
	}
}
 
Example 10
Source File: Tools.java    From ChatRoom with Apache License 2.0 6 votes vote down vote up
public static void setFrameCenter(Container c) {
    //��ȡ���߶���
    Toolkit tk = Toolkit.getDefaultToolkit();

    //��ȡ��Ļ�Ŀ�͸�
    Dimension d = tk.getScreenSize();
    double srceenWidth = d.getWidth();
    double srceenHeigth = d.getHeight();

    //��ȡ����Ŀ�͸�
    int frameWidth = c.getWidth();
    int frameHeight = c.getHeight();

    //��ȡ�µĿ�͸�
    int width = (int) (srceenWidth - frameWidth) / 2;
    int height = (int) (srceenHeigth - frameHeight) / 2;

    //��������
    c.setLocation(width, height);
}
 
Example 11
Source File: HorizontalLayout.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void layoutContainer(final Container parent) {
    final Insets insets = parent.getInsets();
    int posX = insets.left;
    final int posY = insets.top;
    final int height = parent.getHeight() - insets.top - insets.bottom;

    for (Component comp : parent.getComponents()) {
        if (comp.isVisible()) {
            Dimension pref = comp.getPreferredSize();
            if (proportionalHeight) {
                int h = Math.min(pref.height, height);
                int o = (height - h) / 2;
                comp.setBounds(posX, posY + o, pref.width, h);
            } else {
                comp.setBounds(posX, posY, pref.width, height);
            }
            posX += hGap;
            posX += pref.width;
        }
    }
}
 
Example 12
Source File: WindowUtil.java    From StudentSystem with Apache License 2.0 6 votes vote down vote up
public static void setFrameCenter(Container c) {
    //��ȡ���߶���
    Toolkit tk = Toolkit.getDefaultToolkit();

    //��ȡ��Ļ�Ŀ�͸�
    Dimension d = tk.getScreenSize();
    double srceenWidth = d.getWidth();
    double srceenHeigth = d.getHeight();

    //��ȡ����Ŀ�͸�
    int frameWidth = c.getWidth();
    int frameHeight = c.getHeight();

    //��ȡ�µĿ�͸�
    int width = (int) (srceenWidth - frameWidth) / 2;
    int height = (int) (srceenHeigth - frameHeight) / 2;

    //��������
    c.setLocation(width, height);
}
 
Example 13
Source File: JFancyBox.java    From pumpernickel with MIT License 5 votes vote down vote up
public void layoutContainer(Container c) {
	if (c != JFancyBox.this)
		throw new IllegalArgumentException();

	background.setBounds(0, 0, c.getWidth(), c.getHeight());

	Dimension contentSize = contentContainer.getPreferredSize();
	if (contentSize.width < 300) {
		contentSize.width = 300;
	}
	if (contentSize.height < 300) {
		contentSize.height = 300;
	}
	if (contentSize.width > c.getWidth() - 30 && c.getWidth() >= 30) {
		contentSize.width = c.getWidth() - 30;
	}
	if (content instanceof JTextArea) {
		contentSize = TextSize.getPreferredSize((JTextArea) content,
				contentSize.width);
		contentSize.height += 50;
	} else if (contentSize.height > c.getHeight() - 30) {
		contentSize.height = c.getHeight() - 30;
	}
	contentContainer.setBounds(getWidth() / 2 - contentSize.width / 2,
			getHeight() / 2 - contentSize.height / 2,
			contentSize.width, contentSize.height);
	Dimension closeButtonSize = closeButton.getPreferredSize();
	closeButton.setBounds(getWidth() / 2 + contentSize.width / 2
			- closeButtonSize.width / 2, getHeight() / 2
			- contentSize.height / 2 - closeButtonSize.height / 2,
			closeButtonSize.width, closeButtonSize.height);
}
 
Example 14
Source File: DGUI.java    From Geom_Kisrhombille with GNU General Public License v3.0 5 votes vote down vote up
public void paint(Graphics g){
if(dg.image!=null){
  Container c=getContentPane();
  int 
    xoff=(c.getWidth()-dg.imagewidth)/2,
    yoff=(c.getHeight()-dg.imageheight)/2;
  t.setToIdentity();
  t.translate(xoff,yoff);
  Graphics2D h=(Graphics2D)c.getGraphics();
  h.drawImage(dg.image,t,null);}}
 
Example 15
Source File: Drifter.java    From Forsythia with GNU General Public License v3.0 5 votes vote down vote up
public double getViewportFittingScale(){
double hexspan=getCompositionHexagonSpan()*2.0/GD.SQRT3;
Container cp=ui.getContentPane();
int cpw=cp.getWidth(),cph=cp.getHeight();
double 
  s0=hexspan/cpw,
  s1=hexspan/cph;
double scale=Math.min(s0,s1);
return scale;}
 
Example 16
Source File: ShadowPopupFactory.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/**
 * If needed paint dirty region of the snapshot
 *
 * @param shadowBg
 *           BufferedImage
 * @param layeredPane
 *           Container
 */
private void paintShadow(final BufferedImage shadowBg, final Container layeredPane) {
	final int layeredPaneWidth = layeredPane.getWidth();
	final int layeredPaneHeight = layeredPane.getHeight();

	if (RECT.x + RECT.width > layeredPaneWidth) {
		RECT.width = layeredPaneWidth - RECT.x;
	}
	if (RECT.y + RECT.height > layeredPaneHeight) {
		RECT.height = layeredPaneHeight - RECT.y;
	}
	if (!RECT.isEmpty()) {
		final Graphics g = shadowBg.createGraphics();
		g.translate(-RECT.x, -RECT.y);
		g.setClip(RECT);
		if (layeredPane instanceof JComponent) {
			final JComponent c = (JComponent) layeredPane;
			final boolean doubleBuffered = c.isDoubleBuffered();
			c.setDoubleBuffered(false);
			c.paintAll(g);
			c.setDoubleBuffered(doubleBuffered);
		} else {
			layeredPane.paintAll(g);
		}
		g.dispose();
	}
}
 
Example 17
Source File: DefaultTabbedContainerUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void layoutContainer(Container parent) {
    JComponent c = tabDisplayer;
    
    Object orientation = c.getClientProperty (
        TabDisplayer.PROP_ORIENTATION);
    
    Dimension d = tabDisplayer.getPreferredSize();
    Insets ins = container.getInsets();
    int width = parent.getWidth() - (ins.left + ins.right);
    int height = parent.getHeight() - (ins.top + ins.bottom);
    
    if (orientation == TabDisplayer.ORIENTATION_NORTH) {
        c.setBounds (ins.left, ins.top, 
            width, d.height);
        
        contentDisplayer.setBounds (ins.left, ins.top + d.height, 
            width, 
            parent.getHeight() - (d.height + ins.top + ins.bottom));
        
    } else if (orientation == TabDisplayer.ORIENTATION_SOUTH) {
        contentDisplayer.setBounds (ins.top, ins.left, width, 
            parent.getHeight() - (d.height + ins.top + ins.bottom));
        
        c.setBounds (ins.left, parent.getHeight() - (d.height + ins.top + ins.bottom),
            width, d.height);
    } else if (orientation == TabDisplayer.ORIENTATION_EAST) {
        contentDisplayer.setBounds (ins.left, ins.top, width - d.width,
            height);
        
        c.setBounds (parent.getWidth() - (ins.right + d.width), ins.top, 
            d.width, height);
        
    } else if (orientation == TabDisplayer.ORIENTATION_WEST) {
        c.setBounds (ins.left, ins.top, d.width, height);
        
        contentDisplayer.setBounds (ins.left + d.width, ins.top, 
            width - d.width, height);
        
    } else {
        throw new IllegalArgumentException ("Unknown orientation: " + orientation);
    }
}
 
Example 18
Source File: DrifterWindow.java    From Forsythia with GNU General Public License v3.0 4 votes vote down vote up
DrifterWindow(Drifter drifter){
  this.drifter=drifter;
  setBounds(400,50,100,100);
  Container c=this.getContentPane();
  int 
    xfat=100-c.getHeight(),
    yfat=100-c.getWidth();
  
  //1080i is 1920 horizontal and 540 vertical pixels
  
  
  setBounds(400,50,1280+xfat,720+yfat);
  setVisible(true);
  setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  
  addKeyListener(new KL());
  
  
}
 
Example 19
Source File: VerticalLayout.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void layoutContainer(Container container) {
  synchronized (container.getTreeLock()) {
    Dimension top = getPreferredSize(myTop);
    Dimension bottom = getPreferredSize(myBottom);
    Dimension center = getPreferredSize(myCenter);

    Insets insets = container.getInsets();
    int width = container.getWidth() - insets.left - insets.right;
    int height = container.getHeight() - insets.top - insets.bottom;

    int topY = 0;
    if (top != null) {
      topY = myGap + layout(myTop, 0, width, insets);
    }
    int bottomY = height;
    if (bottom != null) {
      bottomY -= bottom.height;
    }
    if (bottomY < topY) {
      bottomY = topY;
    }
    if (center != null) {
      int centerY = (height - center.height) / 2;
      if (centerY > topY) {
        int centerBottomY = centerY + center.height + myGap + myGap;
        if (centerBottomY > bottomY) {
          centerY = bottomY - center.height - myGap - myGap;
        }
      }
      if (centerY < topY) {
        centerY = topY;
      }
      centerY = myGap + layout(myCenter, centerY, width, insets);
      if (bottomY < centerY) {
        bottomY = centerY;
      }
    }
    if (bottom != null) {
      layout(myBottom, bottomY, width, insets);
    }
  }
}