JBuider9 项目转移到 Eclipse 中出错.请教!
import com.borland.jbcl.layout.*;
出错 Eclipse 好象没有这个功能
如何解决啊
import datechooser.DateChooser;
出错
如何解决啊
如上两个基本错误导致程序很多布局出错!
如何解决啊,请教高手!
问题点数:0、回复次数:3Top
1 楼wu_bjcn(咖啡的味道)回复于 2005-05-04 14:24:32 得分 0
你大概是用了Borland的VerticalFlowLayout吧?没有好的办法,必须把你Import的类给加过来。
我也遇到过类似的问题,那时,自己动手改了一下Sun JDK中的FlowLayout,改成了竖排版的(也就是VerticalFlowLayout),代码如下,希望对你有帮助:
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
public class VerticalFlowLayout implements LayoutManager {
/**
* This value indicates that each row of components should be left-justified.
*/
public static final int LEFT = 0;
/**
* This value indicates that each row of components should be center-justified.
*/
public static final int CENTER = 1;
/**
* This value indicates that each row of components should be right-justified.
*/
public static final int RIGHT = 2;
/**
* <code>align</code> is the property that determines
* how each row distributes empty space.
* It can be one of the following values:
* <ul>
* <code>LEFT</code>
* <code>RIGHT</code>
* <code>CENTER</code>
* </ul>
*/
private int align;
/**
* The vertical flow layout manager allows a seperation of components with
* gaps. The horizontal gap will specify the space between components and
* between the components and the borders of the <code>Container</code>.
*/
private int hgap;
/**
* The vertical flow layout manager allows a seperation of components with
* gaps. The vertical gap will specify the space between rows and between the
* the rows and the borders of the <code>Container</code>.
*/
private int vgap;
/**
* Constructs a new <em>VerticalFlowLayout</em> manager with the indicated
* alignment and the indicated horizontal and vertical gaps.
* The value of the alignment argument must be one of below :
* <p>
* <li>VerticalFlowLayout.LEFT,
* <li>VerticalFlowLayout.RIGHT,
* <li>or VerticalFlowLayout.CENTER.
*/
public VerticalFlowLayout(int align, int hgap, int vgap) {
this.hgap = hgap;
this.vgap = vgap;
setAlignment(align);
}
/**
* Constructs a new <em>VerticalFlowLayout</em> manager with the specified
* alignment and a default 5-unit horizontal and vertical gap.
* The value of the alignment argument must be one of below :
* <p>
* <li>VerticalFlowLayout.LEFT,
* <li>VerticalFlowLayout.RIGHT,
* <li>or VerticalFlowLayout.CENTER.
*/
public VerticalFlowLayout(int align) {
this(align, 5, 5);
}
/**
* Constructs a new <em>VerticalFlowLayout</em> with a left alignment and a
* default 5-unit horizontal and vertical gap.
*/
public VerticalFlowLayout() {
this(LEFT, 5, 5);
}Top
2 楼wu_bjcn(咖啡的味道)回复于 2005-05-04 14:25:02 得分 0
/**
* Adds the specified component to the layout.
* Not used by this class.
*/
public void addLayoutComponent(String name, Component comp) {
// Empty.
}
/**
* Removes the specified component from the layout.
* Not used by this class.
*/
public void removeLayoutComponent(Component comp) {
// Empty.
}
/**
* Returns the preferred dimensions for this layout given the
* visible components in the specified target container.
*
* @param target the container that needs to be laid out
*
* @return the preferred dimensions to lay out the
* subcomponents of the specified container
*/
public Dimension preferredLayoutSize(Container target) {
Dimension dim = new Dimension(0, 0);
int nmembers = target.getComponentCount();
boolean firstVisibleComponent = true;
Component m;
Dimension d;
for (int i = 0; i < nmembers; i++) {
m = target.getComponent(i);
if (m.isVisible()) {
d = m.getPreferredSize();
dim.width = Math.max(dim.width, d.width);
if (firstVisibleComponent)
firstVisibleComponent = false;
else
dim.height += vgap;
dim.height += d.height;
}
}
Insets insets = target.getInsets();
dim.width += insets.left + insets.right + hgap * 2;
dim.height += insets.top + insets.bottom + vgap * 2;
return dim;
}
/**
* Returns the minimum dimensions needed to layout the visible
* components contained in the specified target container.
*
* @param target the container that needs to be laid out
*
* @return the minimum dimensions to lay out the
* subcomponents of the specified container
*/
public Dimension minimumLayoutSize(Container target) {
synchronized (target.getTreeLock()) {
Dimension dim = new Dimension(0, 0);
int nmembers = target.getComponentCount();
Component m;
Dimension d;
for (int i = 0; i < nmembers; i++) {
m = target.getComponent(i);
if (m.isVisible()) {
d = m.getMinimumSize();
dim.width = Math.max(dim.width, d.width);
if (i > 0)
dim.height += vgap;
dim.height += d.height;
}
}
Insets insets = target.getInsets();
dim.width += insets.left + insets.right + hgap * 2;
dim.height += insets.top + insets.bottom + vgap * 2;
return dim;
}
}
/**
* Lays out the container. This method lets each visible component take
* its preferred size by reshaping the components in the target container
* in order to satisfy the alignment of this VerticalFlowLayout object.
*
* @param target the specified component being laid out
*/
public void layoutContainer(Container target) {
Insets insets = target.getInsets();
int maxheight = target.getHeight()
- (insets.top + insets.bottom + vgap * 2);
int nmembers = target.getComponentCount();
int x = insets.left + hgap, y = 0;
int roww = 0, start = 0;
Component m;
Dimension d;
for (int i = 0; i < nmembers; i++) {
m = target.getComponent(i);
if (m.isVisible()) {
d = m.getPreferredSize();
m.setSize(d.width, d.height);
if ((y == 0) || ((y + d.height) <= maxheight)) {
if (y > 0)
y += vgap;
y += d.height;
roww = Math.max(roww, d.width);
} else {
moveComponents(target, x, insets.top + vgap, roww,
maxheight - y, start, i);
y = d.height;
x += hgap + roww;
roww = d.width;
start = i;
}
}
}
moveComponents(target, x, insets.top + vgap, roww, maxheight - y,
start, nmembers);
}
/**
* Sets the alignment for this layout.
* Possible values are
* <ul>
* <li><code>FlowLayout.LEFT</code>
* <li><code>FlowLayout.RIGHT</code>
* <li><code>FlowLayout.CENTER</code>
* </ul>
*
* @param align one of the alignment values shown above
*/
public void setAlignment(int align) {
this.align = align;
}
/**
* Gets the alignment for this layout.
*
* @return the alignment value for this layout
*/
public int getAlignment() {
return align;
}
/**
* Sets the horizontal gap between components and between
* the components and the borders of the Container.
*
* @param hgap the horizontal gap between components
* and between the components and the borders
* of the <code>Container</code>
*/
public void setHgap(int hgap) {
this.hgap = hgap;
}
/**
* Gets the horizontal gap between components and between
* the components and the borders of the Container.
*
* @return the horizontal gap between components
* and between the components and the borders
* of the <code>Container</code>
*/
public int getHgap() {
return hgap;
}
/**
* Sets the vertical gap between components and between
* the components and the borders of the Container.
*
* @param vgap the vertical gap between components
* and between the components and the borders
* of the <code>Container</code>
*/
public void setVgap(int vgap) {
this.vgap = vgap;
}
/**
* Gets the vertical gap between components and between
* the components and the borders of the Container.
*
* @return the vertical gap between components
* and between the components and the borders
* of the <code>Container</code>
*/
public int getVgap() {
return vgap;
}
/**
* Returns a string representation of this VerticalFlowLayout
* object and its values.
*
* @return a string representation of this layout
*/
public String toString() {
String str = "";
switch (align) {
case LEFT:
str = ",align=left";
break;
case CENTER:
str = ",align=center";
break;
case RIGHT:
str = ",align=right";
break;
}
return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + str + "]";
}
/**
* 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 first the first component
* @param last the last component
*/
private void moveComponents(Container target, int x, int y, int width,
int height, int first, int last) {
synchronized (target.getTreeLock()) {
Component m;
for (int i = first; i < last; i++) {
m = target.getComponent(i);
if (m.isVisible()) {
switch (align) {
case LEFT:
m.setLocation(x, y);
break;
case CENTER:
m.setLocation((target.getWidth() - m.getWidth()) / 2, y);
break;
case RIGHT:
m.setLocation(target.getWidth() - x - m.getWidth(), y);
break;
}
y += m.getHeight() + vgap;
}
}
}
}
}Top
3 楼yaoyuan200(遥远)回复于 2005-05-04 17:51:34 得分 0
感谢 wu_bjcn(咖啡的味道)!研究研究!
看来是不大好改,我用了很多XYlayout,错的都是XYlayout。Top




