在java SWT应用程序运行时添加/删除按钮。
我正在编写一个用于操作自定义sqlite DB的应用程序。 数据库非常复杂,它具有树状结构在java SWT应用程序运行时添加/删除按钮。,java,swt,Java,Swt,我正在编写一个用于操作自定义sqlite DB的应用程序。 数据库非常复杂,它具有树状结构 main --->operator1 ------>name ------>address --->operator2 ------>name ------>address ------>tariffs ---------->name ---------->price 我需要一个类似“路径”的东西,以便轻松浏览表格和编辑内容。。。我的数据组织为SWT
main
--->operator1
------>name
------>address
--->operator2
------>name
------>address
------>tariffs
---------->name
---------->price
我需要一个类似“路径”的东西,以便轻松浏览表格和编辑内容。。。我的数据组织为SWT表。我已将SWT.MouseDoubleClick侦听器附加到它。我打算通过双击特定的表行“进入”我的操作员数据。问题是,如何回到“主视图”,我需要某种导航。
我目前的想法是创建一个容器,并在其中添加必要的按钮。近似
请注意,路径创建为连续按钮,水平对齐:
mentis -> Dropbox -> Photos
最大的问题是如何做到这一点;)
我能够创建一个按钮并将其添加到may容器中,但这只在应用程序启动时起作用。我不知道在应用程序运行时如何将按钮添加到我的容器中
在我的主要课堂上,我有这样的东西:
Composite pathBarContainer = new Composite(shell, SWT.BORDER);
pathBarContainer.setSize(shell.getBounds().width, 20);
pathBarContainer.setLayout(new FillLayout(SWT.HORIZONTAL));
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.horizontalSpan = 3;
pathBarContainer.setLayoutData(gridData);
pathBar = new PathBar(pathBarContainer, shell, contentProvider);
pathBar.getPathBar();
这是我的PathBar类:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
public class PathBar {
Composite parent;
Composite pathBar;
Shell mainShell;
ContentProvider contentProvider;
Button mainButton;
Button nextButton;
public PathBar(Composite parent_in, Shell mainShell_in, ContentProvider cp) {
parent = parent_in;
mainShell = mainShell_in;
contentProvider = cp;
pathBar = new Composite(parent, SWT.BORDER_DOT);
//pathBar.setSize(100, 300);
pathBar.setLayout(new GridLayout(10, true));
mainButton = new Button(pathBar, SWT.PUSH);
mainButton.setText("main");
}
public Composite getPathBar() {
return pathBar;
}
public void addMainButton() {
mainButton = new Button(pathBar, SWT.PUSH);
mainButton.setText("main");
pathBar.redraw();
//parent.redraw();
//mainShell.redraw();
}
public void addButton() {
nextButton = new Button(pathBar, SWT.PUSH);
nextButton.setText("sth");
pathBar.redraw();
parent.redraw();
System.out.println("addButton");
}
}
方法addMainButton()和addButton()应该从eventHandler运行。。。附在我的SWT表上
如何解决这个问题?
请帮助:)在添加按钮后,您需要告诉it重新制作布局
pathBar.layout(true);