本文整理汇总了Java中javax.swing.JComponent.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java JComponent.getSize方法的具体用法?Java JComponent.getSize怎么用?Java JComponent.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComponent
的用法示例。
在下文中一共展示了JComponent.getSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateSplitLocation
import javax.swing.JComponent; //导入方法依赖的package包/类
private void updateSplitLocation () {
JComponent parent = (JComponent) panel.getParent();
Dimension dim = parent == null ? new Dimension() : parent.getSize();
if (dim.width <= 0 || dim.height <= 0) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
updateSplitLocation();
}
});
return;
}
FileViewComponent fileComp = getActiveFileComponent();
int preferredHeaderHeight = fileComp.getPreferredHeaderHeight();
int preferredHeight = fileComp.getPreferredHeight();
int optimalLocation = preferredHeight + preferredHeaderHeight + 5;
if (optimalLocation > dim.height / 3) {
optimalLocation = dim.height / 3;
}
if (optimalLocation <= preferredHeaderHeight) {
optimalLocation = preferredHeaderHeight * 3;
}
if (dividerSet && panel.splitPane.getDividerLocation() <= optimalLocation) return;
panel.splitPane.setDividerLocation(optimalLocation);
dividerSet = true;
}
示例2: getComponentImage
import javax.swing.JComponent; //导入方法依赖的package包/类
private Image getComponentImage(JComponent component) {
// Initial component sizing & layout
component.setSize((getClientSize().width == 0) ? component.getPreferredSize() : getClientSize()); // try to fit the component to ComponentMorpher
component.doLayout(); // layout component
// Correct component sizing & layout
component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
component.doLayout(); // layout component
// One more iteration because of nested JTextAreas
component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
component.doLayout(); // layout component
// Paint component into BufferedImage
BufferedImage componentImage = new BufferedImage(component.getSize().width, component.getSize().height,
BufferedImage.TYPE_INT_RGB);
component.printAll(componentImage.getGraphics());
return componentImage;
}
示例3: paint
import javax.swing.JComponent; //导入方法依赖的package包/类
public void paint( Graphics g, JComponent c ) {
Dimension s = c.getSize();
if (((JSeparator) c).getOrientation() == JSeparator.HORIZONTAL) {
g.setColor(lineColorHorizontal);
g.drawLine(1, 5, s.width - 2, 5);
} else {
g.setColor(lineColorVertical);
g.drawLine(0, 1, 0, s.height - 2);
}
}
示例4: paintBackground
import javax.swing.JComponent; //导入方法依赖的package包/类
private void paintBackground (final Graphics g, final JComponent c) {
Dimension size = c.getSize();
Graphics2D g2 = (Graphics2D) g;
g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
g.setColor (c.getBackground ());
g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
示例5: paintBox
import javax.swing.JComponent; //导入方法依赖的package包/类
/**
* Draws the combobox itself.
*/
private void paintBox(Graphics g, JComponent c) {
int w = c.getWidth();
int h = c.getHeight() - 1;
if (w <= 0 || h <= 0) {
return;
}
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (c.isEnabled()) {
if (Boolean.parseBoolean(String.valueOf(c.getClientProperty(RapidLookTools.PROPERTY_INPUT_BACKGROUND_DARK)))) {
g2.setColor(Colors.COMBOBOX_BACKGROUND_DARK);
} else {
g2.setColor(Colors.COMBOBOX_BACKGROUND);
}
} else {
g2.setColor(Colors.COMBOBOX_BACKGROUND_DISABLED);
}
g2.fillRoundRect(0, 0, w - 1, h, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
// arrow
int ny = c.getSize().height / 2 - 3;
int nx = c.getWidth() - 15;
if (isDown && c.isEnabled()) {
nx++;
ny++;
}
g2.translate(nx, ny);
if (c.isEnabled()) {
g2.setColor(Colors.COMBOBOX_ARROW);
} else {
g2.setColor(Colors.COMBOBOX_ARROW_DISABLED);
}
w = 14;
Polygon arrow = new Polygon(new int[] { 0, 4, 8 }, new int[] { 0, 6, 0 }, 3);
g2.fillPolygon(arrow);
g2.translate(-nx, -ny);
}