gpt4 book ai didi

SWT 中的 Java 编程

转载 作者:行者123 更新时间:2023-11-29 07:23:08 24 4
gpt4 key购买 nike

嗨..我在java中有这段代码...

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class testTabs {
static int count;
public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("SWT TabFolder Example");


CTabFolder folder = new CTabFolder(shell,SWT.NONE);
CTabItem item = new CTabItem(folder,SWT.UP);
item.setText("First");


CTabItem item1 = new CTabItem(folder,SWT.UP);
item1.setText("First new");

//---------------------------------------------------

CTabFolder fold = new CTabFolder(folder,SWT.UP);
CTabItem ite = new CTabItem(fold,SWT.UP);
ite.setText("Second");
final Composite test = new Composite(fold,SWT.NONE);
test.setLayout(new RowLayout());
Text tab1 = new Text(test,SWT.NONE);
tab1.setText("Testing");
tab1.setEditable(true);
ite.setControl(test);
item.setControl(fold);

Button add = new Button(test,SWT.PUSH);
add.setText("ADD");
SelectionAdapter adap = new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Composite newcomp = new Composite(test,SWT.BORDER_DASH);
Text testtext = new Text(newcomp,SWT.BORDER_SOLID);
testtext.setText("Inside new Comp");
count++;
System.out.println(count);
Control array[] = shell.getChildren();
System.out.println(array.length);
shell.pack();
}
};

add.addSelectionListener(adap);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch()){
display.sleep();
}
}

}
}

当我运行它时,复合“newcomp”是不可见的..任何人都可以帮助我吗??

最佳答案

如果我修改你的代码只添加一个布局,那么它就可以工作了:

public void widgetSelected(SelectionEvent e) {
Composite newcomp = new Composite(test,SWT.BORDER_DASH);
newcomp.setLayout(new RowLayout());
....

关于SWT 中的 Java 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/750434/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com