下面列出了java.awt.Dimension#setSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Get maximum tick label dimension
* @param g Graphics2D
* @return Maximum tick label dimension
*/
public Dimension getMaxTickDim(Graphics2D g) {
this.updateTickLabels();
Dimension dim = new Dimension();
if (this.tickLabels.isEmpty()) {
return dim;
}
Dimension dim1;
double width = dim.getWidth(), height = dim.getHeight();
for (int i = 0; i < this.tickLabels.size(); i++) {
ChartText ct = this.tickLabels.get(i);
ct.setAngle(this.tickLabelAngle);
dim1 = ct.getTrueDimension(g);
if (width < dim1.getWidth()){
width = dim1.getWidth();
}
if (height < dim1.getHeight()) {
height = dim1.getHeight();
}
}
dim.setSize(width, height);
return dim;
}
/**
* <p>
* 重写方法,设置菜单的最小高度为20, 否则会出现菜单项大小不一致的情况。
* </p>
*
* <p>
* Rewrite method, set the minimum height of the menu is 20, otherwise the
* menu item size will be inconsistent situation.
* </p>
*/
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
Icon checkIcon,
Icon arrowIcon,
int defaultTextIconGap)
{
Dimension dimension = super.getPreferredMenuItemSize(c, checkIcon,
arrowIcon, defaultTextIconGap);
if (dimension != null && dimension.height < 20)
{
dimension.setSize(dimension.width, 20);
}
return dimension;
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
double theta = Math.toRadians(15);
double cos = Math.cos(theta);
double sin = Math.sin(theta);
double xsize = sin * h + cos * w;
double ysize = sin * w + cos * h;
double scale = Math.min(w / xsize, h / ysize);
xsize *= scale;
ysize *= scale;
AffineTransform at = new AffineTransform();
at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
at.translate(sin * h * scale, 0.0);
at.rotate(theta);
g2d.transform(at);
dim.setSize(scaleForTransform(at, dim));
}
CopyLastButton(IApplication app)
{
super();
final SquirrelResources rsrc = app.getResources();
final ImageIcon icon = rsrc.getIcon(SquirrelResources.IImageNames.COPY_SELECTED);
setIcon(icon);
// i18n[SQLPanel.copylastbutton.hint=Copy current SQL history to entry area]
String hint = s_stringMgr.getString("SQLPanel.copylastbutton.hint");
setToolTipText(hint);
Dimension dm = getPreferredSize();
dm.setSize(dm.height, dm.height);
setPreferredSize(dm);
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
copySelectedItemToEntryArea();
}
});
}
/**
* <p>
* 重写方法,设置菜单的最小高度为20, 否则会出现菜单项大小不一致的情况。
* </p>
*
* <p>
* Rewrite method, set the minimum height of the menu is 20, otherwise the
* menu item size will be inconsistent situation.
* </p>
*/
protected Dimension getPreferredMenuItemSize(JComponent c,
Icon checkIcon,
Icon arrowIcon,
int defaultTextIconGap)
{
Dimension dimension = super.getPreferredMenuItemSize(c, checkIcon,
arrowIcon, defaultTextIconGap);
if (dimension != null && dimension.height < 20)
{
dimension.setSize(dimension.width, 20);
}
return dimension;
}
public void tooglePanel(){
Dimension size = simulatePanel_.getPreferredSize();
hideBar_ = !hideBar_;
if(hideBar_){
//simulatePanel_.getHideBar_().setText("<");
size.setSize(0, size.height < 800? 800: size.height);
}
else{
//simulatePanel_.getHideBar_().setText(">");
size.setSize(size.width+155, size.height < 800? 800: size.height);
}
setMinimumSize(new Dimension(size.width+50,400));
editPanel_.setMinimumSize(new Dimension(size.width, size.height));
//editPanel_.setSize(new Dimension(size.width, size.height));
this.revalidate();
this.repaint();
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
double theta = Math.toRadians(15);
double cos = Math.cos(theta);
double sin = Math.sin(theta);
double xsize = sin * h + cos * w;
double ysize = sin * w + cos * h;
double scale = Math.min(w / xsize, h / ysize);
xsize *= scale;
ysize *= scale;
AffineTransform at = new AffineTransform();
at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
at.translate(sin * h * scale, 0.0);
at.rotate(theta);
g2d.transform(at);
dim.setSize(scaleForTransform(at, dim));
}
/**
* Calculate the width needed to display the maximum line number
*/
private void setPreferredWidth()
{
Element root = component.getDocument().getDefaultRootElement();
int lines = root.getElementCount();
int digits = Math.max(String.valueOf(lines).length(), minimumDisplayDigits);
// Update sizes when number of digits in the line number changes
if (lastDigits != digits)
{
lastDigits = digits;
FontMetrics fontMetrics = getFontMetrics( getFont() );
int width = fontMetrics.charWidth( '0' ) * digits;
Insets insets = getInsets();
int preferredWidth = insets.left + insets.right + width;
Dimension d = getPreferredSize();
d.setSize(preferredWidth, HEIGHT);
setPreferredSize( d );
setSize( d );
}
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
AffineTransform at = new AffineTransform();
at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
at.shear(0.1, 0.0);
g2d.transform(at);
dim.setSize(scaleForTransform(at, dim));
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
AffineTransform at = new AffineTransform();
at.scale(2.0, 2.0);
g2d.transform(at);
dim.setSize(w/2, h/2);
ctx.pixscale = 4;
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
AffineTransform at = new AffineTransform();
at.translate(1.5, 1.5);
g2d.transform(at);
dim.setSize(w-3, h-3);
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
AffineTransform at = new AffineTransform();
at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
at.shear(0.1, 0.0);
g2d.transform(at);
dim.setSize(scaleForTransform(at, dim));
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
AffineTransform at = new AffineTransform();
at.scale(2.0, 2.0);
g2d.transform(at);
dim.setSize(w/2, h/2);
ctx.pixscale = 4;
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
AffineTransform at = new AffineTransform();
at.scale(2.0, 2.0);
g2d.transform(at);
dim.setSize(w/2, h/2);
ctx.pixscale = 4;
}
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
int w = dim.width;
int h = dim.height;
AffineTransform at = new AffineTransform();
at.scale(2.0, 2.0);
g2d.transform(at);
dim.setSize(w/2, h/2);
ctx.pixscale = 4;
}
/**
* Compute the source region and destination dimensions taking any
* parameter settings into account.
*/
private static void computeRegions(Rectangle sourceBounds,
Dimension destSize,
ImageWriteParam p) {
ImageWriteParam param;
int periodX = 1;
int periodY = 1;
if (p != null) {
int[] sourceBands = p.getSourceBands();
if (sourceBands != null &&
(sourceBands.length != 1 ||
sourceBands[0] != 0)) {
throw new IllegalArgumentException("Cannot sub-band image!");
}
// Get source region and subsampling factors
Rectangle sourceRegion = p.getSourceRegion();
if (sourceRegion != null) {
// Clip to actual image bounds
sourceRegion = sourceRegion.intersection(sourceBounds);
sourceBounds.setBounds(sourceRegion);
}
// Adjust for subsampling offsets
int gridX = p.getSubsamplingXOffset();
int gridY = p.getSubsamplingYOffset();
sourceBounds.x += gridX;
sourceBounds.y += gridY;
sourceBounds.width -= gridX;
sourceBounds.height -= gridY;
// Get subsampling factors
periodX = p.getSourceXSubsampling();
periodY = p.getSourceYSubsampling();
}
// Compute output dimensions
destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
(sourceBounds.height + periodY - 1)/periodY);
if (destSize.width <= 0 || destSize.height <= 0) {
throw new IllegalArgumentException("Empty source region!");
}
}
/**
* Compute the source region and destination dimensions taking any
* parameter settings into account.
*/
private static void computeRegions(Rectangle sourceBounds,
Dimension destSize,
ImageWriteParam p) {
ImageWriteParam param;
int periodX = 1;
int periodY = 1;
if (p != null) {
int[] sourceBands = p.getSourceBands();
if (sourceBands != null &&
(sourceBands.length != 1 ||
sourceBands[0] != 0)) {
throw new IllegalArgumentException("Cannot sub-band image!");
}
// Get source region and subsampling factors
Rectangle sourceRegion = p.getSourceRegion();
if (sourceRegion != null) {
// Clip to actual image bounds
sourceRegion = sourceRegion.intersection(sourceBounds);
sourceBounds.setBounds(sourceRegion);
}
// Adjust for subsampling offsets
int gridX = p.getSubsamplingXOffset();
int gridY = p.getSubsamplingYOffset();
sourceBounds.x += gridX;
sourceBounds.y += gridY;
sourceBounds.width -= gridX;
sourceBounds.height -= gridY;
// Get subsampling factors
periodX = p.getSourceXSubsampling();
periodY = p.getSourceYSubsampling();
}
// Compute output dimensions
destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
(sourceBounds.height + periodY - 1)/periodY);
if (destSize.width <= 0 || destSize.height <= 0) {
throw new IllegalArgumentException("Empty source region!");
}
}
/**
* Compute the source region and destination dimensions taking any
* parameter settings into account.
*/
private static void computeRegions(Rectangle sourceBounds,
Dimension destSize,
ImageWriteParam p) {
ImageWriteParam param;
int periodX = 1;
int periodY = 1;
if (p != null) {
int[] sourceBands = p.getSourceBands();
if (sourceBands != null &&
(sourceBands.length != 1 ||
sourceBands[0] != 0)) {
throw new IllegalArgumentException("Cannot sub-band image!");
}
// Get source region and subsampling factors
Rectangle sourceRegion = p.getSourceRegion();
if (sourceRegion != null) {
// Clip to actual image bounds
sourceRegion = sourceRegion.intersection(sourceBounds);
sourceBounds.setBounds(sourceRegion);
}
// Adjust for subsampling offsets
int gridX = p.getSubsamplingXOffset();
int gridY = p.getSubsamplingYOffset();
sourceBounds.x += gridX;
sourceBounds.y += gridY;
sourceBounds.width -= gridX;
sourceBounds.height -= gridY;
// Get subsampling factors
periodX = p.getSourceXSubsampling();
periodY = p.getSourceYSubsampling();
}
// Compute output dimensions
destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
(sourceBounds.height + periodY - 1)/periodY);
if (destSize.width <= 0 || destSize.height <= 0) {
throw new IllegalArgumentException("Empty source region!");
}
}
public static void setPreferredHeight(final JComponent component, final int height) {
final Dimension size = component.getPreferredSize();
size.setSize(size.getWidth(), JBUI.scale(height));
component.setPreferredSize(size);
}
@Override
public Dimension getPreferredSize() {
Dimension prefSize = super.getPreferredSize();
prefSize.setSize(prefSize.getWidth() + 75, prefSize.getHeight() + 20);
return prefSize;
}