我试图将 JFree 步骤图作为插件添加到 Eclipse 中的可 ScrollView 中,但每次我修改 View 的尺寸时,图表都会不断调整大小(有点随机)。
我想将它们设置为固定大小,无论 View 可能大小(这就是我首先将其设置为可滚动的原因),所以我尝试了这样的操作:
public void createPartControl(final Composite parent) {
ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
Composite comp = new Composite(scrolled, SWT.NONE);
comp.setLayout(new FillLayout(SWT.VERTICAL));
final JFreeChart chart = createChart();
ChartComposite chartComposite1 = new ChartComposite(comp, SWT.NONE, chart, true);
// set chart size attempt
chartComposite1.setSize(500, 200);
chartComposite1.redraw();
comp.redraw();
scrolled.redraw();
// ScrolledComposite stuff
scrolled.setContent(comp);
scrolled.setExpandVertical(true);
scrolled.setExpandHorizontal(true);
scrolled.setAlwaysShowScrollBars(true);
scrolled.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
org.eclipse.swt.graphics.Rectangle r = scrolled.getClientArea();
scrolled.setMinSize(parent.computeSize(r.width, SWT.DEFAULT));
}
});
但它没有做任何事情。当我修改 View 的大小时,图表会自动调整大小。
有什么帮助吗?
最佳答案
确保您了解布局在 SWT 中的工作原理。 Understanding Layouts in SWT是一个好的开始。
chartComposite1.setSize()
没有用,它会被 comp.setLayout( ... )
中设置的布局覆盖>.
...并强制控件进行 redraw()
也没有帮助,因为它不会更新控件的位置或大小。
As I suggested earlier ,如果您知道图表的大小,请使用单列 GridLayout
并通过 GridData::widthHint
和 heightHint
控制图表的大小.
关于java - 在 SWT 中将 JFreeChart ChartComposite 设置为固定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502260/