本文整理汇总了Java中java.awt.Component.doLayout方法的典型用法代码示例。如果您正苦于以下问题:Java Component.doLayout方法的具体用法?Java Component.doLayout怎么用?Java Component.doLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.doLayout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setComponent
import java.awt.Component; //导入方法依赖的package包/类
/**
* Set the cell renderer we will proxy.
*/
public void setComponent (Component jc, JComponent owner) {
Dimension dd = jc.getPreferredSize();
Rectangle currentScreenBounds = Utilities.getUsableScreenBounds();
// get some reasonable limit for the width
int width = Math.min(dd.width, 2 * currentScreenBounds.width);
int height = Math.min(dd.height + 2, 2 * currentScreenBounds.height);
Image nue = !Utilities.isMac() ? owner.createVolatileImage(width, height) :
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = nue.getGraphics();
g.setColor (bg);
g.fillRect (0, 0, width, dd.height + 2);
if( jc instanceof Container && !jc.isValid() ) {
//#214739
jc.setSize( width, dd.height );
jc.doLayout();
}
SwingUtilities.paintComponent(g, jc, this, 0, 0, width, dd.height + 2);
g.dispose();
setImage (nue);
}
示例2: redispatchComponent
import java.awt.Component; //导入方法依赖的package包/类
private boolean redispatchComponent(MouseEvent e) {
Point p = e.getPoint();
int index = list.locationToIndex(p);
if (index < 0 || index >= list.getModel().getSize()) {
return false;
}
ListCellRenderer renderer = list.getCellRenderer();
if (null == renderer) {
return false;
}
Component renComponent = renderer.getListCellRendererComponent(list, list.getModel().getElementAt(index), index, false, false);
if (null == renComponent) {
return false;
}
Rectangle rect = list.getCellBounds(index, index);
if (null == rect) {
return false;
}
renComponent.setBounds(0, 0, rect.width, rect.height);
renComponent.doLayout();
Point p3 = rect.getLocation();
Point p2 = new Point(p.x - p3.x, p.y - p3.y);
Component dispatchComponent =
SwingUtilities.getDeepestComponentAt(renComponent,
p2.x, p2.y);
if ( e.isPopupTrigger() &&
dispatchComponent instanceof LinkButton &&
!((LinkButton)dispatchComponent).isHandlingPopupEvents() )
{
return false;
}
if (dispatchComponent instanceof AbstractButton) {
if (!((AbstractButton) dispatchComponent).isEnabled()) {
return false;
}
Point p4 = SwingUtilities.convertPoint(renComponent, p2, dispatchComponent);
MouseEvent newEvent = new MouseEvent(dispatchComponent,
e.getID(),
e.getWhen(),
e.getModifiers(),
p4.x, p4.y,
e.getClickCount(),
e.isPopupTrigger(),
MouseEvent.NOBUTTON);
dispatchComponent.dispatchEvent(newEvent);
list.repaint(rect);
e.consume();
return true;
}
return false;
}