小妹新接触Swing、JGraph、digester有些小问题请大家帮忙。
双击图片以后弹出另外一个窗口,这个功能已经实现了,可是发现图片可双击的范围非常的小。
好象是应该叫焦点范围吧,请问怎么能把这个焦点范围变大,变的跟我的图片一样大呢?
还有老板要做一些界面美化的工作,请问Swing中,美化主要用的类在什么地方啊?茫然
双击图片以后弹出另外一个窗口,这个功能已经实现了,可是发现图片可双击的范围非常的小。
好象是应该叫焦点范围吧,请问怎么能把这个焦点范围变大,变的跟我的图片一样大呢?
还有老板要做一些界面美化的工作,请问Swing中,美化主要用的类在什么地方啊?茫然
SynthLookAndFeel synth = new SynthLookAndFeel();
synth.load(SynthFrame.class.getResourceAsStream("look_1.xml"), SynthFrame.class);
UIManager.setLookAndFeel(synth);对于 Synth,最重要的是要理解它是 XML 代码,而不是 Java 代码。
例如下面定义一个按钮:
<style id="button">
//...这里描述按钮的颜色、字体、边框等属性
</style>
<bind style="button" type="region" key="JButton"/>javax.swing.plaf.synth
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/synth/package-summary.html还有就是通过设置组件的Border、Background等来进行美化。
看你们的美工如何设计吧。
代码贴一小段,太多了,没办法都放上。哭了,再弄不出来我就下岗了。public class XPDLJGraphMouseListener extends MouseAdapter {
private XPDLJGraph graph;
private PortView curPort; public XPDLJGraphMouseListener(XPDLJGraph graph) {
this.graph = graph;
} public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
curPort = getSourcePortAt(e.getPoint());
if (curPort != null && curPort.getCell() != null) {
Object cell = ((DefaultPort) curPort.getCell()).getParent(); if (cell instanceof ActivityCell) {
WorkflowActivity activity = ((ActivityCell) cell).
getActivity();
String activityType = activity.getType(); if ("ACTIVITY_BEGIN".equals(activityType)) {
new BeginActivityDialog(activity.getId(),
activity.getName(),
activity.getDescription(),
e.getPoint().getX(),
e.getPoint().getY(),
Double.parseDouble(activity.
getWidth()),
Double.parseDouble(activity.
getHeight()));
} else if ("ACTIVITY_SUBFLOW".equals(activityType)) {
new SubflowActivityDialog(activity.getId(),
activity.getName(),
activity.getDescription(),
activity.getSubFlow(),
e.getPoint().getX(),
e.getPoint().getY(),
Double.parseDouble(activity.
getWidth()),
Double.parseDouble(activity.
getHeight()));
}
}
} else {
e.consume();
return;
}
}
}
//在画布上添加节点
public void mouseReleased(MouseEvent e) {
curPort = getSourcePortAt(e.getPoint());
if (curPort != null && curPort.getCell() != null) {
Object cell = ((DefaultPort) curPort.getCell()).getParent();
if (cell instanceof TransitionCell) {
System.out.println("TransitionReleased");
} else if (cell instanceof ActivityCell) {
WorkflowActivity activity = ((ActivityCell) cell).
getActivity();
activity.setX(String.valueOf(e.getPoint().getX()));
activity.setY(String.valueOf(e.getPoint().getY()));
Util.getCurrentPorcess().getWorkflowActivities().
setWorkflowActivity(activity);
} } else if (Util.getCurrentCellType() != null) {
if (Util.getCurrentPackageId() == null) {
JOptionPane.showMessageDialog(Util.getFrame(), "请选择要编辑的流程",
"注意", 1);
return;
} else {
String type = Util.getCurrentCellType();
WorkflowProcess process = Util.getCurrentPorcess();
WorkflowActivities activities = process.getWorkflowActivities();
if (activities == null) {
activities = new WorkflowActivities();
process.setWorkflowActivities(activities);
}
Iterator keys = activities.keySet().iterator();
WorkflowActivity activity;
if (type.equals("ACTIVITY_BEGIN")) {
while (keys.hasNext()) {
activity = activities.getWorkflowActivity(keys.next().
toString());
if (activity.getType().equals("ACTIVITY_BEGIN")) {
return;
}
}
}
if (!flag) {
JOptionPane.showMessageDialog(Util.getFrame(),
"请先添加开始节点和结束节点",
"注意", 1);
return;
}
}
graph.insertActivity(e.getPoint(), false, null,
Util.getCurrentCellType());
Util.setCurrentCellType("SELECT");
}
} else {
e.consume();
return;
}
} public PortView getSourcePortAt(Point point) {
graph.setJumpToDefaultPort(false);
PortView result;
try {
result = graph.getPortViewAt(point.getX(), point.getY());
} finally {
graph.setJumpToDefaultPort(true);
}
return result;
}}
假设你的图片对象的类型是ImageIcon,使用getIconWidth()和getIconHeight()。
如果是Image,稍微麻烦一点,用getHeight(observer), getWidth(observer)。在这里,你的用来显示图片的部件就是observer。