2014-06-11 3 views
0

다른 라벨 위에 라벨을 부착 할 수 있습니까? 특정 배경색의 레이블이 있고 그 위에 다른 배경색으로 두 번째 레이블을 붙이고 싶습니다.다른 라벨 위에 어떻게 라벨을 붙일 수 있습니까?

그럴 수 있습니까? 나는 smallBar를 bigBar 위에 놓고 싶습니다. 다양한 이벤트에서 smallBar의 크기를 변경하여 끊임없이 정상에 올리고 싶습니다.

public class GuessBarComposite extends Composite{ 
    public GuessBarComposite(Composite shell, int style){ 
    super(shell,style); 
    bigBar = new Label(this,SWT.NONE); 
    smallBar = new Label(this, SWT.NONE); 

    Color outOfRangeColor= new Color(Display.getDefault(), 139,0,0); 
    Color inRangeColor= new Color(Display.getDefault(), 255,140,0); 

    bigBar.setBounds(labelOffset,20,barWidth, barHeight); 
    bigBar.setBackground(outOfRangeColor); 

    smallBar.setBounds(labelOffset,20,barWidth-20, barHeight); 
    smallBar.setBackground(inRangeColor); 
    } 
} 
+0

시겠습니까 :

public static void main(String args[]) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("StackOverflow"); shell.setLayout(new GridLayout(1, false)); final StackLayout stackLayout = new StackLayout(); final Composite stack = new Composite(shell, SWT.NONE); stack.setLayout(stackLayout); Label bottom = new Label(stack, SWT.NONE); bottom.setText("Bottom"); Label top = new Label(stack, SWT.NONE); top.setText("Top"); stackLayout.topControl = top; Button button = new Button(shell, SWT.PUSH); button.setText("Switch"); button.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event arg0) { stackLayout.topControl = stackLayout.topControl.equals(top) ? bottom : top; stack.layout(true, true); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!shell.getDisplay().readAndDispatch()) shell.getDisplay().sleep(); } } 

는 단순히 그들 (y 위치의 측면에서 위쪽) 하나씩을 표시 할 경우는, 다음 GridLayout 사용 코드를 제공 하시겠습니까? 가능해야합니다. –

답변

1

당신은 서로의 상단에 Label의 위치를 ​​위해 StackLayout을 사용할 수 있습니다 그리고 당신은 StackLayout#topControl를 설정하여 전환 할 수 있습니다. 다음은 예입니다 : 당신은

public static void main(String args[]) 
{ 
    Display display = new Display(); 
    final Shell shell = new Shell(display); 
    shell.setText("StackOverflow"); 
    shell.setLayout(new GridLayout(1, false)); 

    Label bottom = new Label(shell, SWT.NONE); 
    bottom.setText("Bottom"); 

    Label top = new Label(shell, SWT.NONE); 
    top.setText("Top"); 

    shell.pack(); 
    shell.open(); 

    while (!shell.isDisposed()) 
    { 
     if (!shell.getDisplay().readAndDispatch()) 
      shell.getDisplay().sleep(); 
    } 
} 
+0

고마워요! 나는 그리드 레이아웃을 사용했고 또한 top.moveAbove (bottom) – OHT

관련 문제