我想在应用程序中使用一些控件 - 垂直方向 - 。但是我找不到这样做的可能性。即使是非公开的setOrientation方法也只能解决从左到右的方向。 有没有可能实施自定义Button
或从Canvas
派生?是否可以垂直SWT控制?
回答
据我所知,按钮和标签的垂直方向是不可能的。 您将需要为其提供自定义实现。 查看此链接http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg30094.html
它的一个耻辱,但生病有做它自己:(也许e4将改善 – kostja 2010-10-01 11:29:39
@ kostja - e4仍然会使用SWT和原生控件,只要这些原生控件不提供垂直定向或某种旋转的控件或组件,除了完全基于java的控件(比如Swing)之外别无他法, – 2010-10-04 06:38:33
SWT使用主机操作系统提供的标准小部件。所以如果操作系统不支持垂直导向控件,SWT也不能提供它。
是的,它可能在SWT
使用自定义小部件。您需要自己制作Button
/Label
。 在PaintListener
中,获取Transform
对象并将文本旋转至所需的角度。 在每次点击的示例中,将角度更改为此序列0,90,180,270。 button
(这里实际上是Canvas
)长宽比通过设置bounds
进行更改。 随意玩paint
方法;
public class RotatingButton extends Canvas
{
private int mouse = 0;
private boolean hit = false;
private String text = "Button";
float rotatingAngle = 0f;
float[] angles = { 0, 90, 180, 270 };
int index = 0;
public RotatingButton(Composite parent, int style)
{
super(parent, style);
this.addListener(SWT.MouseUp, new Listener()
{
@Override
public void handleEvent(Event e)
{
index++;
index = index > 3 ? 0 : index;
Rectangle r = getBounds();
setBounds(r.x, r.y, r.height, r.width);
rotatingAngle = angles[index];
redraw();
}
});
this.addPaintListener(new PaintListener()
{
public void paintControl(PaintEvent e)
{
paint(e);
}
});
this.addMouseMoveListener(new MouseMoveListener()
{
public void mouseMove(MouseEvent e)
{
if (!hit)
return;
mouse = 2;
if (e.x < 0 || e.y < 0 || e.x > getBounds().width
|| e.y > getBounds().height)
{
mouse = 0;
}
redraw();
}
});
this.addMouseTrackListener(new MouseTrackAdapter()
{
public void mouseEnter(MouseEvent e)
{
mouse = 1;
redraw();
}
public void mouseExit(MouseEvent e)
{
mouse = 0;
redraw();
}
});
this.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
hit = true;
mouse = 2;
redraw();
}
public void mouseUp(MouseEvent e)
{
hit = false;
mouse = 1;
if (e.x < 0 || e.y < 0 || e.x > getBounds().width
|| e.y > getBounds().height)
{
mouse = 0;
}
redraw();
if (mouse == 1)
notifyListeners(SWT.Selection, new Event());
}
});
this.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
if (e.keyCode == '\r' || e.character == ' ')
{
Event event = new Event();
notifyListeners(SWT.Selection, event);
}
}
});
}
public void setText(String string)
{
this.text = string;
redraw();
}
public void paint(PaintEvent e)
{
Transform tr = null;
tr = new Transform(e.display);
Rectangle r =getBounds();
text=e.gc.stringExtent(text)+"";
e.gc.setAntialias(SWT.ON);
Point p=e.gc.stringExtent(text);
int w = e.width;
int h = e.height;
tr.translate(w/2, h/2);
tr.rotate(rotatingAngle);
e.gc.setTransform(tr);
e.gc.drawString(text, r.x-(p.x/3)*2,r.y-p.y);
}
}
- 1. 是否可以使用python matplotlib垂直绘制一个绘图?
- 2. 是否可以绘制像IntelliJ IDEA中的垂直缩进线?
- 3. 是否可以将预制件与表面垂直对齐?
- 4. SWT TabFolder垂直方向
- 5. 控制垂直轴编号
- 6. 垂直区域以及图表上的线 - 是否可能
- 7. 是否可以使用交替的垂直列填充DataGridView?
- 8. 是否可以垂直居中多行标签?
- 9. 是否可以在表格中垂直居中多列?
- 10. 是否可以使用POS for .NET垂直打印条形码?
- 11. 是否可以使用CSS垂直显示表格行?
- 12. 是否可以使用css3进行垂直文本溢出?
- 13. 是否可以在Primefaces中创建垂直菜单栏?
- 14. 是否可以创建zedgraph垂直标记?
- 15. 是否可以使用richfaces实现垂直选项卡?
- 16. 是否可以垂直对齐div元素?
- 17. 是否可以在Android中支持垂直打字?
- 18. 是否可以垂直居中生成的内容?
- 19. 是否可以在PDF宽度XHtmlRenderer中创建垂直文本?
- 20. 是否可以将DAN中的SPAN垂直居中?
- 21. 检查是否可以检查控制?
- 22. 是否可以控制Mixer.Info字符集?
- 23. 是否可以控制.attr的速度?
- 24. 是否可以控制CPU内核?
- 25. 通过控制绘制垂直线
- 26. C#垂直制表符控制
- 27. 一个SWT控件拒绝“抓取多余的垂直空间”
- 28. 是可以控制
- 29. UIScrollView与垂直滚动页面控制
- 30. 垂直滚动时的冻结控制
现在你可以做到这一点。看看http://stackoverflow.com/q/8091920/796559 – 2011-12-03 17:38:58
@Tonny谢谢,这是一个合理的解决方法 – kostja 2011-12-04 17:51:24