本文整理汇总了Java中java.awt.Component.setLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Component.setLocation方法的具体用法?Java Component.setLocation怎么用?Java Component.setLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.setLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setLocation
import java.awt.Component; //导入方法依赖的package包/类
/**
*
* @Title: setLocation
* @Description: set component's location
* @param @param c
* @return void
* @throws
*/
public static void setLocation(Component c)
{
int winWidth = c.getWidth();
int winHeight = c.getHeight();
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
c.setLocation(screenWidth / 2 - winWidth / 2, screenHeight / 2 - winHeight / 2);
}
示例2: layoutContainer
import java.awt.Component; //导入方法依赖的package包/类
public void layoutContainer(Container target) {
synchronized (target.getTreeLock()) {
Insets insets = target.getInsets();
int maxwidth = parent.getWidth() - (insets.left + insets.right);
int nmembers = target.getComponentCount();
int x = insets.left, y = insets.top;
for (int i = 0 ; i < nmembers ; i++) {
Component m = target.getComponent(i);
if (m.isVisible()) {
Dimension d = m.getPreferredSize();
m.setSize(maxwidth, d.height);
m.setLocation(x, y);
y += d.height;
}
}
}
}
示例3: layout
import java.awt.Component; //导入方法依赖的package包/类
public void layout () {
Table table = getTable();
Insets insets = table.getInsets();
super.layout(insets.left, insets.top, //
table.getWidth() - insets.left - insets.right, //
table.getHeight() - insets.top - insets.bottom);
List<Cell> cells = getCells();
for (int i = 0, n = cells.size(); i < n; i++) {
Cell c = cells.get(i);
if (c.getIgnore()) continue;
Component component = (Component)c.getWidget();
component.setLocation((int)c.getWidgetX(), (int)c.getWidgetY());
component.setSize((int)c.getWidgetWidth(), (int)c.getWidgetHeight());
}
if (getDebug() != Debug.none) SwingToolkit.startDebugTimer();
}
示例4: add
import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component add(Component comp) {
setsize(comp.getPreferredSize());
Component[] comps = getComponents();
if (comps.length > 0) {
oldComponent = comps[0];
}
if (comp.equals(oldComponent)) {
return super.add(comp);
}
if (oldComponent != null) {
putLayer((JComponent) oldComponent, JLayeredPane.DEFAULT_LAYER);
}
Component returnResult = super.add(comp);
putLayer((JComponent) comp, JLayeredPane.DRAG_LAYER);
comp.setSize(getPreferredSize());
comp.setVisible(true);
comp.setLocation(0, 0 - getPreferredSize().height);
slideFromTop(comp, oldComponent);
return returnResult;
}
示例5: moveComponents
import java.awt.Component; //导入方法依赖的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;
// }
}
}
}
示例6: relMove
import java.awt.Component; //导入方法依赖的package包/类
protected void relMove(Container target, int dx, int dy, int rowStart,
int rowEnd) {
synchronized (target.getTreeLock()) {
for (int i = rowStart; i < rowEnd; i++) {
Component m = target.getComponent(i);
// if (m.isVisible()) {
m.setLocation(m.getX() + dx, m.getY() + dy);
// }
}
}
}
示例7: layoutContainer
import java.awt.Component; //导入方法依赖的package包/类
public void layoutContainer(Container c) {
Insets insets = c.getInsets();
int height = yInset + insets.top;
Component[] children = c.getComponents();
Dimension compSize = null;
for (Component child : children) {
compSize = child.getPreferredSize();
child.setSize(compSize.width, compSize.height);
child.setLocation(xInset + insets.left, height);
height += compSize.height + yGap;
}
}
示例8: sort
import java.awt.Component; //导入方法依赖的package包/类
public void sort() {
List<Component> icons = new ArrayList<>();
for (Component comp : getComponents()) {
if (comp instanceof JInternalFrame.JDesktopIcon) {
icons.add(comp);
}
}
int x = 0;
for (Component icon : icons) {
int y = getHeight() - icon.getHeight();
icon.setLocation(x, y);
x += icon.getWidth();
setLayer(icon, 10);
}
}
示例9: layoutContainer
import java.awt.Component; //导入方法依赖的package包/类
/**
* Description of the Method
*
* @param target
* Description of Parameter
*/
@Override
public void layoutContainer(Container target){
synchronized(target.getTreeLock()){
Insets insets=target.getInsets();
int maxheight=target.getHeight()-(insets.top+insets.bottom+_vgap*2);
int nmembers=target.getComponentCount();
int y=0;
Dimension preferredSize=preferredLayoutSize(target);
Dimension targetSize=target.getSize();
switch(_valign){
case TOP:
y=insets.top;
break;
case CENTER:
y=(targetSize.height-preferredSize.height)/2;
break;
case BOTTOM:
y=targetSize.height-preferredSize.height-insets.bottom;
break;
}
for(int i=0;i<nmembers;i++){
Component m=target.getComponent(i);
if(m.isVisible()){
Dimension d=m.getPreferredSize();
m.setSize(d.width, d.height);
if(y+d.height<=maxheight){
if(y>0){
y+=_vgap;
}
int x=0;
switch(_halign){
case LEFT:
x=insets.left;
break;
case CENTER:
x=(targetSize.width-d.width)/2;
break;
case RIGHT:
x=targetSize.width-d.width-insets.right;
break;
}
m.setLocation(x, y);
y+=d.getHeight();
}else{
break;
}
}
}
}
}
示例10: paintTabContent
import java.awt.Component; //导入方法依赖的package包/类
@Override
protected void paintTabContent(Graphics g, int index, String text, int x,
int y, int width, int height) {
// substract lower border
height--;
FontMetrics fm = getTxtFontMetrics();
// setting font already here to compute string width correctly
g.setFont(getTxtFont());
int txtWidth = width;
if (isSelected(index)) {
Component buttons = getControlButtons();
if( null != buttons ) {
Dimension buttonsSize = buttons.getPreferredSize();
if( width < buttonsSize.width+2*ICON_X_PAD ) {
buttons.setVisible( false );
} else {
buttons.setVisible( true );
txtWidth = width - (buttonsSize.width + 2*ICON_X_PAD + TXT_X_PAD);
buttons.setLocation(x + txtWidth + TXT_X_PAD+ICON_X_PAD, y + (height - buttonsSize.height)/2 + (TXT_Y_PAD / 2));
}
}
} else {
txtWidth = width - 2 * TXT_X_PAD;
}
// draw bump (dragger)
drawBump(g, index, x + 4, y + 6, BUMP_WIDTH, height - 8);
boolean slidedOut = false;
WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo();
if( null != winsysInfo && winsysInfo.isSlidedOutContainer() )
slidedOut = false;
if( isTabBusy( index ) && !slidedOut ) {
Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) );
txtWidth -= busyIcon.getIconWidth() - 3 - TXT_X_PAD;
busyIcon.paintIcon( displayer, g, x+TXT_X_PAD, y+(height-busyIcon.getIconHeight())/2);
x += busyIcon.getIconWidth() + 3;
}
// draw text in right color
Color txtC = UIManager.getColor("TabbedPane.foreground"); //NOI18N
HtmlRenderer.renderString(text, g, x + TXT_X_PAD, y + fm.getAscent()
+ TXT_Y_PAD,
txtWidth, height, getTxtFont(),
txtC,
HtmlRenderer.STYLE_TRUNCATE, true);
}
示例11: paintTabContent
import java.awt.Component; //导入方法依赖的package包/类
@Override
protected void paintTabContent(Graphics g, int index, String text, int x,
int y, int width, int height) {
FontMetrics fm = getTxtFontMetrics();
// setting font already here to compute string width correctly
g.setFont(getTxtFont());
int textW = width;
if (isSelected(index)) {
Component buttons = getControlButtons();
if( null != buttons ) {
Dimension buttonsSize = buttons.getPreferredSize();
if( width < buttonsSize.width+ICON_X_PAD ) {
buttons.setVisible( false );
} else {
buttons.setVisible( true );
textW = width - (buttonsSize.width + ICON_X_PAD + 2*TXT_X_PAD);
buttons.setLocation( x + textW+2*TXT_X_PAD-2, y + (height-buttonsSize.height)/2 );
}
}
} else {
textW = width - 2 * TXT_X_PAD;
}
if (text.length() == 0) {
return;
}
int textHeight = fm.getHeight();
int textY;
int textX = x + TXT_X_PAD;
if (index == 0)
textX = x + 5;
if (textHeight > height) {
textY = (-1 * ((textHeight - height) / 2)) + fm.getAscent()
- 1;
} else {
textY = (height / 2) - (textHeight / 2) + fm.getAscent();
}
boolean slidedOut = false;
WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo();
if( null != winsysInfo && winsysInfo.isSlidedOutContainer() )
slidedOut = false;
if( isTabBusy( index ) && !slidedOut ) {
Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) );
textW -= busyIcon.getIconWidth() - 3 - TXT_X_PAD;
busyIcon.paintIcon( displayer, g, textX, y+(height-busyIcon.getIconHeight())/2);
textX += busyIcon.getIconWidth() + 3;
}
int realTextWidth = (int)HtmlRenderer.renderString(text, g, textX, textY, textW, height, getTxtFont(),
UIManager.getColor("textText"), //NOI18N
HtmlRenderer.STYLE_TRUNCATE, false);
realTextWidth = Math.min(realTextWidth, textW);
if( textW > realTextWidth )
textX += (textW - realTextWidth) / 2;
HtmlRenderer.renderString(text, g, textX, textY, textW, height, getTxtFont(),
UIManager.getColor("textText"),
HtmlRenderer.STYLE_TRUNCATE, true);
}
示例12: paintTabContent
import java.awt.Component; //导入方法依赖的package包/类
@Override
protected void paintTabContent(Graphics g, int index, String text, int x,
int y, int width, int height) {
// substract lower border
height--;
y -= 2; //align to center
FontMetrics fm = getTxtFontMetrics();
// setting font already here to compute string width correctly
g.setFont(getTxtFont());
int txtWidth = width;
if (isSelected(index)) {
Component buttons = getControlButtons();
if( null != buttons ) {
Dimension buttonsSize = buttons.getPreferredSize();
if( width < buttonsSize.width+ICON_X_PAD ) {
buttons.setVisible( false );
} else {
buttons.setVisible( true );
txtWidth = width - (buttonsSize.width + ICON_X_PAD + TXT_X_PAD);
buttons.setLocation( x + txtWidth+TXT_X_PAD, y + (height-buttonsSize.height)/2+1 );
}
}
} else {
txtWidth = width - 2 * TXT_X_PAD;
}
if( isUseStretchingTabs() ) {
// draw bump (dragger)
drawBump(g, index, x + 4, y + 6, BUMP_WIDTH, height - 8);
}
boolean slidedOut = false;
WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo();
if( null != winsysInfo && winsysInfo.isSlidedOutContainer() )
slidedOut = false;
if( isTabBusy( index ) && !slidedOut ) {
Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) );
txtWidth -= busyIcon.getIconWidth() + 3 + TXT_X_PAD;
busyIcon.paintIcon( displayer, g, x+TXT_X_PAD, y+(height-busyIcon.getIconHeight())/2+1);
x += busyIcon.getIconWidth() + 3;
}
// draw text in right color
Color txtC = UIManager.getColor("TabbedPane.foreground"); //NOI18N
HtmlRenderer.renderString(text, g, x + TXT_X_PAD, y + fm.getAscent()
+ TXT_Y_PAD,
txtWidth, height, getTxtFont(),
txtC,
HtmlRenderer.STYLE_TRUNCATE, true);
}
示例13: paintTabContent
import java.awt.Component; //导入方法依赖的package包/类
protected void paintTabContent(Graphics g, int index, String text, int x,
int y, int width, int height) {
// substract lower border
height--;
FontMetrics fm = getTxtFontMetrics();
// setting font already here to compute string width correctly
g.setFont(getTxtFont());
int txtWidth = width;
if (isSelected(index)) {
Component buttons = getControlButtons();
if( null != buttons ) {
Dimension buttonsSize = buttons.getPreferredSize();
if( width < buttonsSize.width+ICON_X_PAD ) {
buttons.setVisible( false );
} else {
buttons.setVisible( true );
txtWidth = width - (buttonsSize.width + ICON_X_PAD + TXT_X_PAD);
buttons.setLocation(x + txtWidth + TXT_X_PAD, y + (height - buttonsSize.height)/2 + (TXT_Y_PAD / 2));
}
}
} else {
txtWidth = width - 2 * TXT_X_PAD;
}
// draw bump (dragger)
drawBump(g, index, x + 4, y + 6, BUMP_WIDTH, height - 8);
boolean slidedOut = false;
WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo();
if( null != winsysInfo && winsysInfo.isSlidedOutContainer() )
slidedOut = false;
if( isTabBusy( index ) && !slidedOut ) {
Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) );
txtWidth -= busyIcon.getIconWidth() - 3 - TXT_X_PAD;
busyIcon.paintIcon( displayer, g, x+TXT_X_PAD, y+(height-busyIcon.getIconHeight())/2);
x += busyIcon.getIconWidth() + 3;
}
// draw text in right color
Color txtC = UIManager.getColor("textText"); //NOI18N
HtmlRenderer.renderString(text, g, x + TXT_X_PAD, y + fm.getAscent()
+ TXT_Y_PAD,
txtWidth, height, getTxtFont(),
txtC,
HtmlRenderer.STYLE_TRUNCATE, true);
}
示例14: paintTabContent
import java.awt.Component; //导入方法依赖的package包/类
@Override
protected void paintTabContent(Graphics g, int index, String text, int x,
int y, int width, int height) {
FontMetrics fm = getTxtFontMetrics();
// setting font already here to compute string width correctly
g.setFont(getTxtFont());
if( 0 == index )
x++;
int txtWidth = width;
if (isSelected(index)) {
Component buttons = getControlButtons();
if( null != buttons ) {
Dimension buttonsSize = buttons.getPreferredSize();
if( width < buttonsSize.width+ICON_X_PAD ) {
buttons.setVisible( false );
} else {
buttons.setVisible( true );
txtWidth = width - (buttonsSize.width + ICON_X_PAD + 2*TXT_X_PAD);
buttons.setLocation( x + txtWidth+2*TXT_X_PAD, y + (height-buttonsSize.height)/2+getButtonYPadding() );
}
}
} else {
txtWidth = width - 2 * TXT_X_PAD;
}
if( isUseStretchingTabs() ) {
// draw bump (dragger)
ColorUtil.paintVistaTabDragTexture(getDisplayer(), g, x + BUMP_X_PAD, y
+ BUMP_Y_PAD_UPPER, height - (BUMP_Y_PAD_UPPER
+ BUMP_Y_PAD_BOTTOM));
}
boolean slidedOut = false;
WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo();
if( null != winsysInfo && winsysInfo.isSlidedOutContainer() )
slidedOut = false;
if( isTabBusy( index ) && !slidedOut ) {
Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) );
txtWidth -= busyIcon.getIconWidth() - 3 - TXT_X_PAD;
busyIcon.paintIcon( displayer, g, x+TXT_X_PAD, y+(height-busyIcon.getIconHeight())/2);
x += busyIcon.getIconWidth() + 3;
}
HtmlRenderer.renderString(text, g, x + TXT_X_PAD, y + fm.getAscent()
+ TXT_Y_PAD, txtWidth, height, getTxtFont(),
txtC,
HtmlRenderer.STYLE_TRUNCATE, true);
}
示例15: placethem
import java.awt.Component; //导入方法依赖的package包/类
/**
* places the components defined by first to last within the target
* container using the bounds box defined.
*
* @param target
* the container.
* @param x
* the x coordinate of the area.
* @param y
* the y coordinate of the area.
* @param width
* the width of the area.
* @param height
* the height of the area.
* @param first
* the first component of the container to place.
* @param last
* the last component of the container to place.
*/
private void placethem(Container target, int x, int y, int width,
int height, int first, int last) {
int align = getAlignment();
if (align == MIDDLE)
y += height / 2;
if (align == BOTTOM)
y += height;
for (int i = first; i < last; i++) {
Component m = target.getComponent(i);
Dimension md = m.getSize();
if (m.isVisible()) {
int px = x + (width - md.width) / 2;
m.setLocation(px, y);
y += vgap + md.height;
}
}
}