本文整理匯總了Java中java.awt.Container.getComponentCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Container.getComponentCount方法的具體用法?Java Container.getComponentCount怎麽用?Java Container.getComponentCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Container
的用法示例。
在下文中一共展示了Container.getComponentCount方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: minimumLayoutSize
import java.awt.Container; //導入方法依賴的package包/類
/**
* Returns the minimum size needed to layout the target container.
*
* @param target
* the component to lay out.
* @return the minimum layout dimension.
*/
public Dimension minimumLayoutSize(Container target) {
Dimension tarsiz = new Dimension(0, 0);
for (int i = 0; i < target.getComponentCount(); i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getMinimumSize();
tarsiz.width = Math.max(tarsiz.width, d.width);
if (i > 0) {
tarsiz.height += vgap;
}
tarsiz.height += d.height;
}
}
Insets insets = target.getInsets();
tarsiz.width += insets.left + insets.right + hgap * 2;
tarsiz.height += insets.top + insets.bottom + vgap * 2;
return tarsiz;
}
示例2: layoutContainer
import java.awt.Container; //導入方法依賴的package包/類
public void layoutContainer(Container target) {
super.layoutContainer(target);
base.getLayout().layoutContainer(base);
final Dimension viewSize = base.getViewport().getSize();
final Insets insets = base.getInsets();
viewSize.width += insets.left;
viewSize.height += insets.top;
// prevent non-base components from overlapping the base's scrollbars
final int n = target.getComponentCount();
for (int i = 0; i < n; ++i) {
Component c = target.getComponent(i);
if (c != base && c.isVisible()) {
final Rectangle b = c.getBounds();
b.width = Math.min(b.width, viewSize.width);
b.height = Math.min(b.height, viewSize.height);
c.setBounds(b);
}
}
}
示例3: setButtonState
import java.awt.Container; //導入方法依賴的package包/類
static void setButtonState(Container c, String buttonString, boolean flag) {
int len = c.getComponentCount();
for (int i = 0; i < len; i++) {
Component comp = c.getComponent(i);
if (comp instanceof JButton) {
JButton b = (JButton) comp;
if (buttonString.equals(b.getText())) {
b.setEnabled(flag);
}
} else if (comp instanceof Container) {
setButtonState((Container) comp, buttonString, flag);
}
}
}
示例4: paintBorder
import java.awt.Container; //導入方法依賴的package包/類
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
g.setColor(color);
g.fillRect(x, y, width, height);
if( c instanceof Container )
{
Container cont = (Container) c;
for( int i = 0, n = cont.getComponentCount(); i < n; i++ )
{
Component comp = cont.getComponent(i);
comp.getBounds(r);
Graphics tmpg = g.create(r.x, r.y, r.width, r.height);
comp.paint(tmpg);
tmpg.dispose();
}
}
}
示例5: preferredLayoutSize
import java.awt.Container; //導入方法依賴的package包/類
@Override
public Dimension preferredLayoutSize(Container container)
{
Dimension dimension = new Dimension(0, 0);
for( int i = 0; i < container.getComponentCount(); i++ )
{
Component component = container.getComponent(i);
if( component.isVisible() )
{
Dimension dimension1 = component.getPreferredSize();
dimension.width = Math.max(dimension.width, dimension1.width);
if( i > 0 )
{
dimension.height += hgap;
}
dimension.height += dimension1.height;
}
}
Insets insets = container.getInsets();
dimension.width += insets.left + insets.right + hgap * 2;
dimension.height += insets.top + insets.bottom + vgap * 2;
return dimension;
}
示例6: getAllFrames
import java.awt.Container; //導入方法依賴的package包/類
private static Collection<JInternalFrame> getAllFrames(Container parent) {
int i, count;
Collection<JInternalFrame> results = new LinkedHashSet<>();
count = parent.getComponentCount();
for (i = 0; i < count; i++) {
Component next = parent.getComponent(i);
if (next instanceof JInternalFrame) {
results.add((JInternalFrame) next);
} else if (next instanceof JInternalFrame.JDesktopIcon) {
JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
if (tmp != null) {
results.add(tmp);
}
} else if (next instanceof Container) {
results.addAll(getAllFrames((Container) next));
}
}
return results;
}
示例7: found
import java.awt.Container; //導入方法依賴的package包/類
protected List<IJavaElement> found(List<IJavaElement> pElements, IJavaAgent driver) {
List<IJavaElement> r = new ArrayList<IJavaElement>();
for (IJavaElement je : pElements) {
Component component = je.getComponent();
if (!(component instanceof Container)) {
continue;
}
int index = getIndexOfComponentInParent(component);
if (index < 0) {
continue;
}
Container parent = component.getParent();
JWindow topContainer = driver.switchTo().getTopContainer();
for (int i = index + 1; i < parent.getComponentCount(); i++) {
Component c = parent.getComponent(i);
IJavaElement je2 = JavaElementFactory.createElement(c, driver, driver.switchTo().getTopContainer());
if (sibling.matchesSelector(je2).size() > 0) {
IJavaElement e = topContainer.addElement(JavaElementFactory.createElement(c, driver, topContainer));
if (!r.contains(e)) {
r.add(e);
}
}
}
}
return r;
}
示例8: addKeyListeners
import java.awt.Container; //導入方法依賴的package包/類
/**
* Adds a feature to the KeyListeners attribute of the FileChooserFixer object
*
* @param c The feature to be added to the KeyListeners attribute
*/
private void addKeyListeners(Container c) {
for (int i = 0; i < c.getComponentCount(); i++) {
Component d = c.getComponent(i);
if (d instanceof Container) {
addKeyListeners((Container) d);
}
d.addKeyListener(this);
}
}
示例9: minimumLayoutSize
import java.awt.Container; //導入方法依賴的package包/類
/**
* Description of the Method
*
* @param target
* Description of Parameter
* @return Description of the Returned Value
*/
@Override
public Dimension minimumLayoutSize(Container target){
synchronized(target.getTreeLock()){
Dimension dim=new Dimension(0, 0);
int nmembers=target.getComponentCount();
boolean firstVisibleComponent=true;
for(int ii=0;ii<nmembers;ii++){
Component m=target.getComponent(ii);
if(m.isVisible()){
Dimension d=m.getPreferredSize();
dim.width=Math.max(dim.width, d.width);
if(firstVisibleComponent){
firstVisibleComponent=false;
}else{
dim.height+=_vgap;
}
dim.height+=d.height;
}
}
Insets insets=target.getInsets();
dim.width+=insets.left+insets.right+_hgap*2;
dim.height+=insets.top+insets.bottom+_vgap*2;
return dim;
}
}
示例10: preferredLayoutSize
import java.awt.Container; //導入方法依賴的package包/類
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, Utils.checkedInt(chart.getChartContext().getViewHeight()));
for (int i = 0; i < parent.getComponentCount(); i++)
dim.width = Math.max(dim.width, parent.getComponent(i).
getPreferredSize().width);
return dim;
}
示例11: layoutSize
import java.awt.Container; //導入方法依賴的package包/類
/**
* Returns the minimum or preferred dimension needed to layout the target
* container.
*
* @param target target to get layout size for
* @param preferred should preferred size be calculated
* @return the dimension to layout the target container
*/
private Dimension layoutSize(final Container target, final boolean preferred) {
synchronized (target.getTreeLock()) {
// Each row must fit with the width allocated to the containter.
// When the container width = 0, the preferred width of the container
// has not yet been calculated so lets ask for the maximum.
int targetWidth = target.getSize().width;
if (targetWidth == 0) {
targetWidth = Integer.MAX_VALUE;
}
final int hgap = getHgap();
final int vgap = getVgap();
final Insets insets = target.getInsets();
final int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
final int maxWidth = targetWidth - horizontalInsetsAndGap;
// Fit components into the allowed width
final Dimension dim = new Dimension(0, 0);
int rowWidth = 0;
int rowHeight = 0;
final int nmembers = target.getComponentCount();
for (int i = 0; i < nmembers; i++) {
final Component m = target.getComponent(i);
if (m.isVisible()) {
final Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
// Can't add the component to current row. Start a new row.
if (rowWidth + d.width > maxWidth) {
addRow(dim, rowWidth, rowHeight);
rowWidth = 0;
rowHeight = 0;
}
// Add a horizontal gap for all components after the first
if (rowWidth != 0) {
rowWidth += hgap;
}
rowWidth += d.width;
rowHeight = Math.max(rowHeight, d.height);
}
}
addRow(dim, rowWidth, rowHeight);
dim.width += horizontalInsetsAndGap;
dim.height += insets.top + insets.bottom + vgap * 2;
// When using a scroll pane or the DecoratedLookAndFeel we need to
// make sure the preferred size is less than the size of the
// target containter so shrinking the container size works
// correctly. Removing the horizontal gap is an easy way to do this.
final Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null && target.isValid()) {
dim.width -= (hgap + 1);
}
return dim;
}
}
示例12: findCachedSheet
import java.awt.Container; //導入方法依賴的package包/類
private NbSheet findCachedSheet( Container c ) {
NbSheet res = null;
int childrenCount = c.getComponentCount();
for( int i=0; i<childrenCount && res == null; i++ ) {
Component child = c.getComponent(i);
if( child instanceof NbSheet ) {
res = (NbSheet)child;
} else if( child instanceof Container ) {
res = findCachedSheet((Container)child);
}
}
return res;
}
示例13: layoutContainer
import java.awt.Container; //導入方法依賴的package包/類
public void layoutContainer(Container parent) {
setParent(parent);
int n = parent.getComponentCount();
getConstraints(parent).reset();
for (int i = 0 ; i < n ; i++) {
getConstraints(parent.getComponent(i)).reset();
}
Insets insets = parent.getInsets();
Constraints pc = getConstraints(parent);
abandonCycles(pc.getX()).setValue(0);
abandonCycles(pc.getY()).setValue(0);
abandonCycles(pc.getWidth()).setValue(parent.getWidth() -
insets.left - insets.right);
abandonCycles(pc.getHeight()).setValue(parent.getHeight() -
insets.top - insets.bottom);
for (int i = 0 ; i < n ; i++) {
Component c = parent.getComponent(i);
Constraints cc = getConstraints(c);
int x = abandonCycles(cc.getX()).getValue();
int y = abandonCycles(cc.getY()).getValue();
int width = abandonCycles(cc.getWidth()).getValue();
int height = abandonCycles(cc.getHeight()).getValue();
c.setBounds(insets.left + x, insets.top + y, width, height);
}
}
示例14: hideVolumeSelector
import java.awt.Container; //導入方法依賴的package包/類
public void hideVolumeSelector( Container c, Vector<String> drives )
{
int len = c.getComponentCount();
for (int i = 0; i < len; i++)
{
Component comp = c.getComponent(i);
if (comp instanceof JComboBox)
{
JComboBox cb = (JComboBox)comp;
// this is the box we want to modify
if (cb.getParent().getParent().getClass().getName().equals("lu.fisch.moenagade.gui.dialogs.OpenProject"))
{
for(int j=cb.getItemCount()-1;j>=0;j--)
{
String name = cb.getItemAt(j).toString();
System.out.println("Checking ... "+name);
boolean remove = true;
for(int d=0;d<drives.size();d++)
if (name.toLowerCase().contains(""+drives.get(d).toCharArray()+"\\"))
remove=false;
if (remove==true)
{
System.out.println("Removing ... "+name);
cb.removeItemAt(j);
}
}
}
}
else if (comp instanceof Container)
{
hideVolumeSelector((Container)comp, drives);
}
}
}
示例15: layoutContainer
import java.awt.Container; //導入方法依賴的package包/類
/**
* Lays out the container.
*
* @param target
* the container to lay out.
*/
public void layoutContainer(Container target) {
Insets insets = target.getInsets();
int maxheight = target.getSize().height
- (insets.top + insets.bottom + vgap * 2);
int maxwidth = target.getSize().width
- (insets.left + insets.right + hgap * 2);
int numcomp = target.getComponentCount();
int x = insets.left + hgap, y = 0;
int colw = 0, start = 0;
for (int i = 0; i < numcomp; i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
// fit last component to remaining height
if ((this.vfill) && (i == (numcomp - 1))) {
d.height = Math.max((maxheight - y),
m.getPreferredSize().height);
}
// fit component size to container width
if (this.hfill) {
m.setSize(maxwidth, d.height);
d.width = maxwidth;
} else {
m.setSize(d.width, d.height);
}
if (y + d.height > maxheight) {
placethem(target, x, insets.top + vgap, colw,
maxheight - y, start, i);
y = d.height;
x += hgap + colw;
colw = d.width;
start = i;
} else {
if (y > 0)
y += vgap;
y += d.height;
colw = Math.max(colw, d.width);
}
}
}
placethem(target, x, insets.top + vgap, colw, maxheight - y, start,
numcomp);
}