本文整理汇总了Java中java.awt.Container.getComponent方法的典型用法代码示例。如果您正苦于以下问题:Java Container.getComponent方法的具体用法?Java Container.getComponent怎么用?Java Container.getComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Container
的用法示例。
在下文中一共展示了Container.getComponent方法的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: 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);
}
}
}
示例3: 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;
}
示例4: 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);
}
}
}
示例5: calcTabs
import java.awt.Container; //导入方法依赖的package包/类
/**
* Figure out tab stop x-positions
* @param target
* @return ruler
*/
protected Ruler calcTabs(Container target) {
Ruler ruler = new Ruler();
int nmembers = target.getComponentCount();
int x = 0;
int tabIndex = 0; // First tab stop
for (int i = 0; i < nmembers; i++) {
Component m = target.getComponent(i);
// if (m.isVisible()) {
if (isFirstInRow(m) || i == 0) {
x = 0;
tabIndex = 0;
} else
x += hgap;
if (hasConstraint(m, TAB_STOP)) {
ruler.setTab(tabIndex, x); // Will only increase
x = ruler.getTab(tabIndex++); // Jump forward if neccesary
}
Dimension d = m.getPreferredSize();
x += d.width;
}
// }
return ruler;
}
示例6: preferredLayoutSize
import java.awt.Container; //导入方法依赖的package包/类
/**
* Description of the Method
*
* @param target
* Description of Parameter
* @return Description of the Returned Value
*/
@Override
public Dimension preferredLayoutSize(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;
}
}
示例7: 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;
}
}
示例8: getSize
import java.awt.Container; //导入方法依赖的package包/类
public Dimension getSize(Container parent, boolean minimum) {
int n = parent.getComponentCount();
Insets insets = parent.getInsets();
Dimension d = new Dimension();
for (int i = 0; i < n; i++) {
Component comp = parent.getComponent(i);
if (comp instanceof EnableButton) {
continue;
}
Dimension p = (minimum
? comp.getMinimumSize()
: comp.getPreferredSize());
if (horizontal) {
d.width += p.width;
if (d.height < p.height) {
d.height = p.height;
}
} else {
if (d.width < p.width) {
d.width = p.width;
}
d.height += p.height;
}
}
d.width += (insets.left + insets.right);
d.height += (insets.top + insets.bottom);
return d;
}
示例9: components
import java.awt.Container; //导入方法依赖的package包/类
protected List<Component> components(Container aContainer) {
List<Component> l = new ArrayList();
for (int i = 0; i < aContainer.getComponentCount(); i++) {
Component c = aContainer.getComponent(i);
if (c instanceof JToolBar || c instanceof JPanel)
l.addAll(components((Container)c));
else if (focusable(c)) l.add(c);
}
return l;
}
示例10: layoutContainer
import java.awt.Container; //导入方法依赖的package包/类
/**
* Lays out the specified container.
* @param parent the container to be laid out
*/
public void layoutContainer(Container parent) {
int n = parent.getComponentCount();
Insets insets = parent.getInsets();
Dimension size = parent.getSize();
int c = horizontal ? insets.left : insets.top;
int x, y;
int ebx = size.width - insets.right;
size.width -= (insets.left + insets.right);
size.height -= (insets.top + insets.bottom);
for (int i = 0; i < n; i++) {
Component comp = parent.getComponent(i);
Dimension pref = comp.getPreferredSize();
if (comp instanceof EnableButton) {
ebx -= 4;
ebx -= pref.width;
x = ebx;
y = (insets.top - pref.height) / 2;
} else if (horizontal) {
x = c;
c += pref.width;
y = insets.top;
pref.height = size.height;
} else {
x = insets.left;
pref.width = size.width;
y = c;
c += pref.height;
}
comp.setBounds(x, y, pref.width, pref.height);
}
}
示例11: 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);
}
}
示例12: moveComponents
import java.awt.Container; //导入方法依赖的package包/类
/**
* Centers the elements in the specified row, if there is any slack.
* @param target the component which needs to be moved
* @param x the x coordinate
* @param y the y coordinate
* @param width the width dimensions
* @param height the height dimensions
* @param rowStart the beginning of the row
* @param rowEnd the the ending of the row
* @param ltr
* @param ruler
*/
protected void moveComponents(Container target, int x, int y, int width,
int height, int rowStart, int rowEnd, boolean ltr, Ruler ruler) {
synchronized (target.getTreeLock()) {
switch (getAlignment()) {
case FlowLayout.LEFT:
x += ltr ? 0 : width;
break;
case FlowLayout.CENTER:
x += width / 2;
break;
case FlowLayout.RIGHT:
x += ltr ? width : 0;
break;
case LEADING:
break;
case TRAILING:
x += width;
break;
}
int tabIndex = 0;
for (int i = rowStart; i < rowEnd; i++) {
Component m = target.getComponent(i);
// if (m.isVisible()) {
if (hasConstraint(m, TAB_STOP))
x = getInsets(target).left + ruler.getTab(tabIndex++);
int dy = (valign == VTOP) ? 0 : (height - m.getHeight()) / 2;
if (ltr) {
m.setLocation(x, y + dy);
} else {
m.setLocation(target.getWidth() - x - m.getWidth(), y + dy);
}
x += m.getWidth() + hgap;
// }
}
}
}
示例13: get
import java.awt.Container; //导入方法依赖的package包/类
private static <T> T get(Class<? extends T> type, Container container) {
Component component = container.getComponent(0);
if (!type.isAssignableFrom(component.getClass())) {
throw new IllegalStateException("expected " + type + "; expected " + component.getClass());
}
return (T) component;
}
示例14: getLists
import java.awt.Container; //导入方法依赖的package包/类
/**
* Gets the lists attribute of the FileChooserFixer object
*
* @param fc Description of the Parameter
* @return The lists value
*/
protected JList[] getLists(JFileChooser fc) {
Vector<Component> v = new Vector<>();
Stack<Component> s = new Stack<>();
s.push(fc);
while (!s.isEmpty()) {
Component c = s.pop();
if (c instanceof Container) {
Container d = (Container) c;
for (int i = 0; i < d.getComponentCount(); i++) {
if (d.getComponent(i) instanceof JList) {
v.add(d.getComponent(i));
} else {
s.push(d.getComponent(i));
}
}
}
}
JList[] arr = new JList[v.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = (JList<?>) v.get(i);
}
return arr;
}
示例15: layoutContainer
import java.awt.Container; //导入方法依赖的package包/类
@Override
public void layoutContainer(Container container)
{
Insets insets = container.getInsets();
int i = container.getSize().height - (insets.top + insets.bottom + vgap * 2);
int j = container.getSize().width - (insets.left + insets.right + hgap * 2);
int k = container.getComponentCount();
int x = insets.left + hgap;
int i1 = 0;
int j1 = 0;
int k1 = 0;
for( int l1 = 0; l1 < k; l1++ )
{
Component component = container.getComponent(l1);
if( component.isVisible() )
{
Dimension dimension = component.getPreferredSize();
if( vfill && l1 == k - 1 )
{
dimension.height = Math.max(i - i1, component.getPreferredSize().height);
}
if( hfill )
{
component.setSize(j, dimension.height);
dimension.width = j;
}
else
{
component.setSize(dimension.width, dimension.height);
}
if( i1 + dimension.height > i )
{
placethem(container, x, insets.top + vgap, i - i1, k1, l1);
i1 = dimension.height;
x += hgap + j1;
j1 = dimension.width;
k1 = l1;
}
else
{
if( i1 > 0 )
{
i1 += vgap;
}
i1 += dimension.height;
j1 = Math.max(j1, dimension.width);
}
}
}
placethem(container, x, insets.top + vgap, i - i1, k1, k);
}