java parentcomponent,Java Component.getParent方法代碼示例

本文整理匯總了Java中com.codename1.ui.Component.getParent方法的典型用法代碼示例。如果您正苦於以下問題:Java Component.getParent方法的具體用法?Java Component.getParent怎麽用?Java Component.getParent使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.codename1.ui.Component的用法示例。

在下文中一共展示了Component.getParent方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: scrollToElement

​點讚 3

import com.codename1.ui.Component; //導入方法依賴的package包/類

/**

* Scrolls the HTMLComponent to the specified element

*

* @param element The element to scroll to (must be contained in the document)

* @param animate true to animate the scrolling, false otherwise

* @throws IllegalArgumentException if the element is not contained in the current document.

*/

public void scrollToElement(HTMLElement element,boolean animate) {

if (!pageLoading()) {

if (!document.contains(element)) {

throw new IllegalArgumentException("The specified element is not contained in the current document.");

}

Vector v=element.getUi();

if ((v!=null) && (v.size()>0)) {

Component cmp=((Component)v.firstElement());

if (cmp!=null) {

Container parent=cmp.getParent();

int y=cmp.getY();

while ((parent!=null) && (parent!=this)) {

y+=parent.getY();

parent=parent.getParent();

}

scrollTo(y , animate);

}

}

} else {

throw new IllegalStateException("Page is still loading");

}

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:30,

示例2: setComponentConstraintsImpl

​點讚 3

import com.codename1.ui.Component; //導入方法依賴的package包/類

/**

* Sets the component constraint for the component that already must be

* handled by this layout manager.

*

* See the class JavaDocs for information on how this string is formatted.

*

* @param constr The component constraints as a String or

* {@link net.miginfocom.layout.CC}. null is ok.

* @param comp The component to set the constraints for.

* @param noCheck Doe not check if the component is handled if true

* @throws RuntimeException if the constraint was not valid.

* @throws IllegalArgumentException If the component is not handling the

* component.

*/

private void setComponentConstraintsImpl(Component comp, Object constr, boolean noCheck) {

Container parent = comp.getParent();

if (noCheck == false && scrConstrMap.containsKey(comp) == false) {

throw new IllegalArgumentException("Component must already be added to parent!");

}

ComponentWrapper cw = new CodenameOneMiGComponentWrapper(comp);

if (constr == null || constr instanceof String) {

String cStr = ConstraintParser.prepare((String) constr);

scrConstrMap.put(comp, constr);

ccMap.put(cw, ConstraintParser.parseComponentConstraint(cStr));

} else if (constr instanceof CC) {

scrConstrMap.put(comp, constr);

ccMap.put(cw, (CC) constr);

} else {

throw new IllegalArgumentException("Constraint must be String or ComponentConstraint: " + constr.getClass().toString());

}

dirty = true;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:40,

示例3: addLayoutComponent

​點讚 3

import com.codename1.ui.Component; //導入方法依賴的package包/類

public void addLayoutComponent(Object constraints, Component comp, Container c) {

GridBagConstraints cons;

if (constraints != null) {

if (!(constraints instanceof GridBagConstraints)) {

throw new IllegalArgumentException("AddLayoutComponent: constraint object must be GridBagConstraints"); //$NON-NLS-1$

}

cons = (GridBagConstraints) constraints;

} else {

if (comptable.containsKey(comp)) {

// don't replace constraints with default ones

return;

}

cons = defaultConstraints;

}

/*try {

//cons.verify();

} catch (IllegalArgumentException e) {

// awt.81=AddLayoutComponent: {0}

throw new IllegalArgumentException("AddLayoutComponent: " + e.getMessage()); //$NON-NLS-1$

}*/

GridBagConstraints consClone = (GridBagConstraints) cons.clone();

comptable.put(comp, consClone);

Container parent = comp.getParent();

updateParentInfo(parent, consClone);

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:26,

示例4: initCompsArray

​點讚 3

import com.codename1.ui.Component; //導入方法依賴的package包/類

private Dimension initCompsArray(Container parent, Component[] components) {

int maxW = 0;

int maxH = 0;

int i = 0;

for (Component comp : comptable.keySet()) {

GridBagConstraints cons = comptable.get(comp);

if ((comp.getParent() == parent) && comp.isVisible()) {

components[i++] = comp;

}

if ((cons.gridx != GridBagConstraints.RELATIVE)

&& (cons.gridy != GridBagConstraints.RELATIVE)) {

maxW = Math.max(maxW, cons.gridx + cons.gridwidth);

maxH = Math.max(maxH, cons.gridy + cons.gridheight);

}

}

return new Dimension(maxW, maxH);

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:18,

示例5: calcPreferredValues

​點讚 3

import com.codename1.ui.Component; //導入方法依賴的package包/類

private void calcPreferredValues(Component cmp) {

if (tmpLaidOut.contains(cmp)) {

return;

}

tmpLaidOut.add(cmp);

LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);

if (constraint != null) {

constraint.fixDependencies(cmp.getParent());

for (LayeredLayoutConstraint.Inset inset : constraint.insets) {

if (inset.referenceComponent != null && inset.referenceComponent.getParent() == cmp.getParent()) {

calcPreferredValues(inset.referenceComponent);

}

inset.calcPreferredValue(cmp.getParent(), cmp);

}

}

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:17,

示例6: replace

​點讚 3

import com.codename1.ui.Component; //導入方法依賴的package包/類

/**

* Removes an existing component replacing it with the specified component.

*

* @param existingComponent the Component that should be removed and

* replaced with newComponent

* @param newComponent the Component to put in existingComponents place

* @throws IllegalArgumentException is either of the Components are null or

* if existingComponent is not being managed by this layout manager

*/

public void replace(Component existingComponent, Component newComponent) {

if (existingComponent == null || newComponent == null) {

throw new IllegalArgumentException("Components must be non-null");

}

// Make sure all the components have been registered, otherwise we may

// not update the correct Springs.

if (springsChanged) {

registerComponents(horizontalGroup, HORIZONTAL);

registerComponents(verticalGroup, VERTICAL);

}

ComponentInfo info = (ComponentInfo)componentInfos.

remove(existingComponent);

if (info == null) {

throw new IllegalArgumentException("Component must already exist");

}

host.removeComponent(existingComponent);

if (newComponent.getParent() != host) {

host.addComponent(newComponent);

}

info.setComponent(newComponent);

componentInfos.put(newComponent, info);

invalidateHost();

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:33,

示例7: hideComponent

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

public void hideComponent(Component c)

{

c.setHeight(0);

c.setPreferredH(0);

if (c.getParent() != null) {

c.getParent().revalidate();

}

c.setVisible(false);

}

開發者ID:martijn00,項目名稱:MusicPlayerCodenameOne,代碼行數:12,

示例8: getVisibleRect

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

private static com.codename1.ui.geom.Rectangle getVisibleRect(Component c) {

com.codename1.ui.geom.Rectangle r = new com.codename1.ui.geom.Rectangle(c.getAbsoluteX() + c.getScrollX(), c.getAbsoluteY() + c.getScrollY(), c.getWidth(), c.getHeight());

while ((c = c.getParent()) != null) {

com.codename1.ui.geom.Rectangle.intersection(r.getX(), r.getY(), r.getWidth(), r.getHeight(),

c.getAbsoluteX() + c.getScrollX(), c.getAbsoluteY() + c.getScrollY(), c.getWidth(), c.getHeight(),

r);

}

return r;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:12,

示例9: isScrollableParent

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

private static boolean isScrollableParent(Component c){

Container p = c.getParent();

Font f = c.getStyle().getFont();

float pixelSize = f == null ? Display.getInstance().convertToPixels(4) : f.getPixelSize();

while( p != null){

if(p.isScrollableY() && p.getAbsoluteY() + p.getScrollY() < Display.getInstance().getDisplayHeight() / 2 - pixelSize * 2){

return true;

}

p = p.getParent();

}

return false;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:14,

示例10: findType

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

public static E findType(Class clazz, Component comp) {

while (comp != null && !clazz.isInstance(comp)) {

comp = comp.getParent();

}

return (E) comp;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:8,

示例11: getRootAncestor

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

/**

* Returns either the parent form or the component below the embedded container

* above c.

*

* @param c the component whose root ancestor we should find

* @return the root

*/

protected Container getRootAncestor(Component c) {

while(c.getParent() != null && !(c.getParent() instanceof EmbeddedContainer)) {

c = c.getParent();

}

if(!(c instanceof Container)) {

return null;

}

return (Container)c;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:17,

示例12: Stats

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

public Stats(Component c) {

name = c.getName();

type = c.getClass().getName();

uiid = c.getUIID();

if(c instanceof Label) {

Image l = ((Label)c).getIcon();

if(l != null) {

imageName = l.getImageName();

}

}

if(c.getParent() != null) {

parentName = c.getParent().getName();

}

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:15,

示例13: setParentsVisible

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

/**

* Turns on the visibilty of all ancestors of the given component

*

* @param cmp The component to work on

*/

private void setParentsVisible(Component cmp) {

Container cont=cmp.getParent();

while (cont!=null) {

cont.setVisible(true);

cont=cont.getParent();

}

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:13,

示例14: clipOnLWUITBounds

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

/**

* Clips the RIM native graphics based on the component hierarchy within LWUIT

* so the native RIM component doesn't paint itself above other components such

* as the forms title.

*/

private int clipOnLWUITBounds(Component lwuitComponent, Graphics rimGraphics) {

int result = 0;

Component parent = lwuitComponent;

while (parent != null) {

int x = parent.getAbsoluteX() + parent.getScrollX();

int y = parent.getAbsoluteY() + parent.getScrollY();

rimGraphics.pushRegion(x, y, parent.getWidth(), parent.getHeight(), 0, 0);

rimGraphics.translate(-rimGraphics.getTranslateX(), -rimGraphics.getTranslateY());

parent = parent.getParent();

result++;

}

return result;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:20,

示例15: expandNodeImpl

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

private Container expandNodeImpl(boolean animate, Component c) {

Container p = c.getParent().getLeadParent();

if(p != null) {

c = p;

}

c.putClientProperty(KEY_EXPANDED, "true");

if(openFolder == null) {

FontImage.setMaterialIcon(c, FontImage.MATERIAL_FOLDER, 3);

} else {

setNodeIcon(openFolder, c);

}

int depth = ((Integer)c.getClientProperty(KEY_DEPTH)).intValue();

Container parent = c.getParent();

Object o = c.getClientProperty(KEY_OBJECT);

Container dest = new Container(new BoxLayout(BoxLayout.Y_AXIS));

parent.addComponent(BorderLayout.CENTER, dest);

buildBranch(o, depth, dest);

if(isInitialized() && animate) {

// prevent a race condition on node expansion contraction

parent.animateHierarchyAndWait(300);

if(multilineMode) {

revalidate();

}

} else {

parent.revalidate();

}

return dest;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:29,

示例16: isParentOf

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

private boolean isParentOf(Container cnt, Component c) {

while(c != null) {

if(c == cnt) {

return true;

}

c = c.getParent();

}

return false;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:10,

示例17: removeLayoutComponent

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

public void removeLayoutComponent(Component comp) {

Container parent = comp.getParent();

if (parent != null) {

getParentInfo(parent).consTable.remove(comptable.get(comp));

}

comptable.remove(comp);

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:8,

示例18: getComponentsNumber

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

private int getComponentsNumber(Container parent) {

int componentsNumber = 0;

for (Component comp : comptable.keySet()) {

if ((comp.getParent() == parent) && comp.isVisible()) {

componentsNumber++;

}

}

return componentsNumber;

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:10,

示例19: paintSlideAtPosition

​點讚 2

import com.codename1.ui.Component; //導入方法依賴的package包/類

private void paintSlideAtPosition(Graphics g, int slideX, int slideY) {

Component source = getSource();

// if this is the first form we can't do a slide transition since we have no source form

if (source == null) {

return;

}

Component dest = getDestination();

int w = source.getWidth();

int h = source.getHeight();

if (slideType == SLIDE_HORIZONTAL) {

h = 0;

} else {

w = 0;

}

boolean dir = forward;

if(dest != null && dest.getUIManager().getLookAndFeel().isRTL() && slideType == SLIDE_HORIZONTAL) {

dir = !dir;

}

if(dir) {

w = -w;

h = -h;

} else {

slideX = -slideX;

slideY = -slideY;

}

g.setClip(source.getAbsoluteX()+source.getScrollX(), source.getAbsoluteY()+source.getScrollY(), source.getWidth(), source.getHeight());

// dialog animation is slightly different...

if(source instanceof Dialog) {

if(buffer != null) {

g.drawImage(buffer, 0, 0);

} else {

paint(g, dest, 0, 0);

}

paint(g, source, -slideX, -slideY);

return;

}

if(dest instanceof Dialog) {

if(buffer != null) {

g.drawImage(buffer, 0, 0);

} else {

paint(g, source, 0, 0);

}

paint(g, dest, -slideX - w, -slideY - h);

return;

}

if(source.getParent() != null || buffer == null) {

source.paintBackgrounds(g);

paint(g, source, slideX , slideY );

} else {

g.drawImage(buffer, slideX, slideY);

}

paint(g, dest, slideX + w, slideY + h);

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:62,

示例20: setHeader

​點讚 1

import com.codename1.ui.Component; //導入方法依賴的package包/類

/**

* Replaces the title for content that was already added. Notice that this will fail if the content isn't

* in yet.

* @param header the new title for the content

* @param body the content that was already added with a different header using addContent

*/

public void setHeader(Component header, Component body) {

AccordionContent ac = (AccordionContent) body.getParent();

ac.header.getParent().replace(ac.header, header, null);

}

開發者ID:codenameone,項目名稱:CodenameOne,代碼行數:11,

注:本文中的com.codename1.ui.Component.getParent方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我的回答有误。在 Java 中,线程是通过一个线程组(ThreadGroup)来组织的,而每个线程组都有一个父线程组。但是,线程并没有直接引用它们的父线程,因此在 Java 中没有 `Thread.getParent()` 方法来获取父线程。 如果你想要打印当前线程和它的父线程的 stack trace,可以使用下面的代码: ```java Thread currentThread = Thread.currentThread(); System.out.println("当前线程:" + currentThread.getName()); StackTraceElement[] currentStackTrace = currentThread.getStackTrace(); System.out.println("当前线程的 stack trace:"); for (StackTraceElement element : currentStackTrace) { System.out.println(element.toString()); } ThreadGroup currentGroup = currentThread.getThreadGroup(); Thread parentThread = currentGroup.getParent().getThreadGroup().getParent().activeCount() > 0 ? currentGroup.getParent().getThreadGroup().getParent().enumerate()[0] : null; if (parentThread != null) { System.out.println("父线程:" + parentThread.getName()); StackTraceElement[] parentStackTrace = parentThread.getStackTrace(); System.out.println("父线程的 stack trace:"); for (StackTraceElement element : parentStackTrace) { System.out.println(element.toString()); } } else { System.out.println("没有父线程!"); } ``` 这段代码首先获取当前线程,然后打印出当前线程的名称,接着获取当前线程的 stack trace 并打印出来。然后获取当前线程所在的线程组,再通过 `ThreadGroup.getParent()` 方法获取当前线程所在线程组的父线程组,进而获取父线程组中的任意一个活动线程(这里我选择获取第一个),最后打印出这个父线程的名称和 stack trace。注意,如果当前线程没有父线程,那么就会打印出“没有父线程!”的提示信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值