Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有可能有垂直SWT控制装置吗?_Java_Swt_Eclipse Rcp - Fatal编程技术网

Java 有可能有垂直SWT控制装置吗?

Java 有可能有垂直SWT控制装置吗?,java,swt,eclipse-rcp,Java,Swt,Eclipse Rcp,我希望在应用程序中有一些控件-按钮s和标签s-垂直方向-。然而,我找不到这样做的可能性。即使是非公共的setOrientation方法也只处理从左到右的方向。 不实现自定义按钮或从画布派生是否可能?SWT使用主机操作系统提供的标准小部件。因此,如果操作系统不支持垂直方向的控件,SWT也不能提供。据我所知,按钮和标签的垂直方向是不可能的。 您将需要为相同的应用程序提供自定义实现。 使用自定义小部件在SWT中检查此链接是否可能。 您需要制作自己的按钮/标签。 在PaintListener中,获取Tr

我希望在应用程序中有一些控件-
按钮
s和
标签
s-垂直方向-。然而,我找不到这样做的可能性。即使是非公共的setOrientation方法也只处理从左到右的方向。
不实现自定义
按钮
或从
画布
派生是否可能?

SWT使用主机操作系统提供的标准小部件。因此,如果操作系统不支持垂直方向的控件,SWT也不能提供。据我所知,按钮和标签的垂直方向是不可能的。 您将需要为相同的应用程序提供自定义实现。
使用自定义小部件在
SWT
中检查此链接是否可能。 您需要制作自己的
按钮
/
标签
。 在
PaintListener
中,获取
Transform
对象并将文本旋转到所需角度。 在每次单击的示例中,将角度更改为该序列0,90180270。
按钮
(此处实际上是
画布
)纵横比通过设置
边界
进行更改。 可以随意使用
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);
}
}
公共类旋转按钮扩展画布
{
私有int鼠标=0;
私有布尔命中=假;
私有字符串text=“Button”;
浮动旋转角度=0f;
浮动[]角度={0,90,180,270};
int指数=0;
公共旋转按钮(复合父级,int样式)
{
超级(父母,风格);
this.addListener(SWT.MouseUp,newlistener())
{
@凌驾
公共无效handleEvent(事件e)
{
索引++;
指数=指数>3?0:指数;
矩形r=getBounds();
立根(r.x、r.y、r.高度、r.宽度);
旋转角度=角度[指数];
重画();
}
});
this.addPaintListener(新的PaintListener()
{
公共无效油漆控制(油漆事件e)
{
油漆(e);
}
});
this.addMouseMoveListener(新的MouseMoveListener()
{
公共无效mouseMove(MouseEvent e)
{
如果(!命中)
返回;
小鼠=2只;
如果(e.x<0 | | e.y<0 | | e.x>getBounds().width
||e.y>getBounds().高度)
{
鼠标=0;
}
重画();
}
});
this.addMouseTrackListener(新的MouseTrackAdapter()
{
公共无效鼠标器(鼠标事件e)
{
小鼠=1;
重画();
}
公共无效mouseExit(MouseEvent e)
{
鼠标=0;
重画();
}
});
this.addMouseListener(新的MouseAdapter()
{
公共无效mouseDown(MouseEvent e)
{
命中=真;
小鼠=2只;
重画();
}
公共无效mouseUp(MouseEvent e)
{
命中=错误;
小鼠=1;
如果(e.x<0 | | e.y<0 | | e.x>getBounds().width
||e.y>getBounds().高度)
{
鼠标=0;
}
重画();
如果(鼠标==1)
notifyListeners(SWT.Selection,new Event());
}
});
this.addKeyListener(新的KeyAdapter()
{
按下公共无效键(按键事件e)
{
if(e.keyCode='\r'| | e.character=='')
{
事件=新事件();
notifyListeners(SWT.Selection,事件);
}
}
});
}
公共void setText(字符串)
{
this.text=字符串;
重画();
}
公共空间油漆(油漆事件e)
{
变换tr=null;
tr=新变换(如显示);
矩形r=getBounds();
text=e.gc.stringExtent(text)+”;
e、 gc.setAntialias(SWT.ON);
点p=e.gc.stringExtent(文本);
int w=e.宽度;
int h=e.高度;
翻译(w/2,h/2);
tr.旋转(旋转角度);
e、 gc.setTransform(tr);
e、 gc.抽绳(文本,r.x-(p.x/3)*2,r.y-p.y);
}
}

很遗憾,但我必须自己做:(也许e4会比以前更好。)that@kostja-e4仍将使用SWT和本机控件。只要这些本机控件不提供控件或组件的垂直方向或某种旋转,除了完全基于java的控件(如Swing)之外就没有其他方法了现在你可以这样做了。看看@Tony谢谢,这是一个合理的解决办法