The case is that the TopTaskGroup(left one) can "grab excess vertical space" while resizing window, but the NewTaskGroup(the right one), after adding a TooBar on it(see the createAddBtnOnGroup method), it doesn't grow as you resize the window. Why is that?
(I have a shell instance with 2-column GridLayout)
Code is here:
private void createTaskWidgets() {
createTopTaskGroup();
createNewTaskGroup();
}
private void createTopTaskGroup() {
Group topTasksGroup = new Group(shell, SWT.SHADOW_NONE);
topTasksGroup.setText(TaskConsts.TOP_TASK_LIST);
topTasksTable = new TaskTable(topTasksGroup, TaskTable.SORT_BY_VOTES, iteration, this);
topTasksTable.setLayoutData(getTableGridData() );
topTasksGroup.setLayout(new GridLayout() );
topTasksGroup.setLayoutData(getTableGridData() );
topTasksGroup.pack();
}
private void createNewTaskGroup() {
Group newTasksGroup = new Group(shell, SWT.SHADOW_NONE);
newTasksGroup.setText(TaskConsts.NEW_TASK_LIST);
newTasksTable = new TaskTable(newTasksGroup, TaskTable.SORT_BY_CREATION_TIME, iteration, this);
topTasksTable.setLayoutData(getTableGridData() );
ToolBar actionToolBar = createAddBtnOnGroup(newTasksGroup);
newTasksGroup.setLayout(new GridLayout() );
newTasksGroup.setLayoutData(getTableGridData() );
newTasksGroup.layout();
newTasksGroup.pack();
// set actionToolBar's location to newTasksGroup's right-top position
actionToolBar.setLocation(
newTasksGroup.getLocation().x + newTasksGroup.getSize().x
- actionToolBar.getSize().x - 5,
newTasksGroup.getLocation().y - 2);
}
private GridData getTableGridData() {
GridData gridData = new GridData(0, SWT.FILL, false, true);
return gridData;
}
private ToolBar createAddBtnOnGroup(Group newTasksGroup) {
ToolBar actionToolBar = new ToolBar(newTasksGroup, SWT.HORIZONTAL | SWT.RIGHT);
addTaskToolItem = new ToolItem(actionToolBar, SWT.PUSH | SWT.RIGHT);
addTaskToolItem.setImage(new Image(display, TaskConsts.ICON_PLUS));
final MainWindow mainWindow = this;
addTaskToolItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
new CreateTask(getShell(), mainWindow);
}
});
GridData gridData = new GridData();
gridData.exclude = true;
actionToolBar.setLayoutData(gridData);
actionToolBar.pack();
return actionToolBar;
}
private void organize() {
GridLayout gridLayout = new GridLayout(2, false);
shell.setLayout(gridLayout);
shell.pack();
}
Thanks in advance~
Thanks for your excellent problem description!
It seems to me that this is a simple copy-paste bug.
The fourth line in your createNewTaskGroup method should not be
topTasksTable.setLayoutData(getTableGridData() );
but
newTasksTable.setLayoutData(getTableGridData() );
Related
I need to put a scroll into a chart without but I can't use javax.swing, just using swt.
I want to put a ilimited number of items in the category axis,maybe 100 or 200, obviously you need a scroll for watching all data in the x axis.
I have implemented the dataset of my chart with SlidingCategoryDataset, but the scroll just working with the slice part of items,
These are the methods which creates the chart and dataset:
private static CategoryDataset createDataset() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (int i = 0; i < 50; i++)
dataset.addValue(Math.random() * 100D, "S1", "S" + i);
return dataset;
}
private static JFreeChart createGraficaY(SlidingCategoryDataset slidingDataSet) {
JFreeChart chart = ChartFactory.createAreaChart(
"",
"",
"Y",
slidingDataSet,
PlotOrientation.VERTICAL,
true,
true,
false
);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
int alpha = 127;
Paint serie_2017 = new Color(0,150,194,alpha);
Paint serie_2018 = new Color(0,216,180,alpha);
AreaRenderer r = new AreaRenderer();
r.setSeriesPaint(0, serie_2017);
r.setSeriesPaint(1, serie_2018);
plot.setRenderer(r);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.BLACK);
plot.setDomainGridlinesVisible(false);
plot.setDomainGridlinePaint(Color.BLACK);
plot.setOutlineVisible(false);
plot.setOutlinePaint(Color.white);
chart.getLegend().setFrame(BlockBorder.NONE);
return chart;
}
This is the main class:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell( display );
shell.setLayout( new FillLayout() );
final ScrolledComposite scrolledComposite = new ScrolledComposite( shell, SWT.H_SCROLL);
scrolledComposite.setExpandVertical( true );
scrolledComposite.setExpandHorizontal( true );
scrolledComposite.setAlwaysShowScrollBars( true );
SlidingCategoryDataset dataset = new SlidingCategoryDataset(createDataset(), 0, 10);
JFreeChart chart =createGraficaY(dataset);
chart.removeLegend();
final ChartComposite chartComposite = new ChartComposite(scrolledComposite, SWT.NONE, chart,
true);
scrolledComposite.setContent(chartComposite);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setMinSize(chartComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
scrolledComposite.addListener( SWT.Resize, event -> {
int width = scrolledComposite.getClientArea().width;
scrolledComposite.setMinSize( shell.computeSize( width, SWT.DEFAULT ) );
} );
shell.setSize( 300, 300 );
shell.open();
while( !shell.isDisposed() ) {
if( !display.readAndDispatch() )
display.sleep();
}
display.dispose();
}
This code doesn't work that I want because just scrolling firstly 10 items:
ScrollCompositeChart_1
ScrollCompositeChart_2
Could you help with this code?
Are there any way to do this only with swt? I can't use swing...
Thanks.
We solved it, the solution was implemented Slider instead of a scrolledComposite:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell( display );
GridLayout gridLayout = new GridLayout(1,true);
shell.setLayout(gridLayout);
GridData gridDataGeneral=new GridData(SWT.FILL,SWT.FILL,true,true);
shell.setLayoutData(gridDataGeneral);
//Creamos la grafica y lo ponemos en el composite
Grafica graficaImpl = new GraficaImpl();
final SlidingCategoryDataset dataset = new SlidingCategoryDataset(createDataset(), 0, 10);
JFreeChart chart =graficaImpl.crearGraficaY(dataset);
chart.removeLegend();
//CHARTCOMPOSITE
//Se coloca en el chartcomposite
final ChartComposite chartComposite = new ChartComposite(shell, SWT.NONE, chart,
true);
GridData gridDatachartComposite=new GridData(SWT.FILL,SWT.FILL,true,true);
chartComposite.setLayoutData(gridDatachartComposite);
//SLIDER
final Slider slider = new Slider(shell, SWT.HORIZONTAL);
slider.setMaximum(100);
slider.setMinimum(0);
slider.setSelection(0);
slider.setIncrement(1);
SelectionListener listener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
dataset.setFirstCategoryIndex(slider.getSelection());
}
};
slider.addSelectionListener(listener);
GridData gridDataSlider=new GridData(SWT.FILL,SWT.BEGINNING,true,true);
slider.setLayoutData(gridDataSlider);
/* */
shell.setSize(500, 300 );
shell.open();
while( !shell.isDisposed() ) {
if( !display.readAndDispatch() )
display.sleep();
}
display.dispose();
}
I am using Tree and in this tree I have a five treecolumn. Also create two treeItem one is parent and other child, put their values in treecolumn by programatically. Now I need a dropdown List(Combobox) in each tree column(except first one) to view the list data. Currently getting only single value. Please see the below code to get tree item values editable in treecolumn.
private void editTreeTable(final Tree table){
final TreeEditor editor = new TreeEditor(table);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
table.addMouseListener(new MouseAdapter() {
#Override
public void mouseUp(final MouseEvent e) {
final Control oldEditor = editor.getEditor();
if (oldEditor != null) {
oldEditor.dispose();
}
final Point p = new Point(e.x, e.y);
final TreeItem item = table.getItem(p);
if (item == null) {
return;
}
for (int i = 1; i < table.getColumnCount(); ++i) {
if (item.getBounds(i).contains(p)) {
final int columnIndex = i;
// The control that will be the editor must be a
final Text newEditor = new Text(table, SWT.NONE);
newEditor.setText(item.getText(columnIndex ));
newEditor.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
final Text text = (Text) editor.getEditor();
editor.getItem().setText(columnIndex , text.getText());
}
});
newEditor.selectAll();
newEditor.setFocus();
editor.setEditor(newEditor, item, columnIndex );
}
}
}
});
}
Now find the below code to get the tree item value from API
private void createTestSuiteTable( final Tree table)
{
//Dispose all elements
TreeItem items[] = table.getItems();
for(int i=0;i<items.length;i++)
{
items[i].dispose();
}
TSGson tsGsons[] = TestSuiteAPIHandler.getInstance().getAllTestSuites();
boolean checked=false;
for (TSGson tsGson : tsGsons)
{
parentTestSuite = new TreeItem(table, SWT.NONE|SWT.MULTI);
parentTestSuite.setText(new String[] { "" +tsGson.tsName, "", "","","","" });
parentTestSuite.setData("EltType","TESTSUITE");
if(tsGson.tsTCLink==null)
continue;
for(TSTCGson tsTCGson : tsGson.tsTCLink)
{
TreeItem trtmTestcases = new TreeItem(parentTestSuite, SWT.NONE|SWT.MULTI);
trtmTestcases.setText(new String[] {tsTCGson.tcName,
tsTCGson.tcParams.get(0)!=null ?tsTCGson.tcParams.get(0).tcparamValue:"",
tsTCGson.tcParams.get(1)!=null ?tsTCGson.tcParams.get(1).tcparamValue:"",
tsTCGson.tcParams.get(2)!=null ?tsTCGson.tcParams.get(2).tcparamValue:"",
"local",
tsTCGson.tcParams.get(4)!=null ?tsTCGson.tcParams.get(4).tcparamValue:"" });
trtmTestcases.setData("EltType","TESTCASE");
table.setSelection(parentTestSuite);
if(checked)
{
trtmTestcases.setChecked(checked);
}
}
}
}
Find the below code for tree column creation in SWT
localHostTable = new Tree(composite_2,SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION | SWT.VIRTUAL);
localHostTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
localHostTable.setLinesVisible(true);
localHostTable.setHeaderVisible(true);
TreeColumn trclmnNewColumn_1 = new TreeColumn(localHostTable, SWT.NONE);
trclmnNewColumn_1.setWidth(113);
trclmnNewColumn_1.setText("TestSuite/TestCase");
TreeColumn trclmnColumn_5 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_5.setWidth(73);
trclmnColumn_5.setText("Exe_Platform");
TreeColumn trclmnColumn_6 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_6.setWidth(77);
trclmnColumn_6.setText("Exe_Type");
TreeColumn trclmnColumn_7 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_7.setWidth(85);
trclmnColumn_7.setText("Run_On");
TreeColumn trclmnColumn_8 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_8.setWidth(81);
trclmnColumn_8.setText("Thread-Count");
final TreeColumn trclmnColumn_9 = new TreeColumn(localHostTable, SWT.NONE);
trclmnColumn_9.setWidth(97);
trclmnColumn_9.setText("Column5");
please suggest
Since there's nothing in your question about Combo or CCombo controls, I can't help you troubleshoot an issue. I also am not going to write your code for you, but I can try to point you in the right direction with a short example.
Yes, i want the combo to always be visible.
You can still use a TreeEditor to accomplish this, and it will actually be simpler than the code snippet you posted with the MouseListener.
Create the CCombo (or Combo) as you would in any other situation, and use TreeEditor.setEditor(...) methods to specify that the CCombo control should be displayed in that cell:
// ...
final CCombo combo = new CCombo(tree, SWT.NONE);
final TreeEditor editor = new TreeEditor(tree);
editor.setEditor(combo, item, 1);
// ...
Full MCVE:
public class TreeComboBoxTest {
private final Display display;
private final Shell shell;
public TreeComboBoxTest() {
display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
final Tree tree = new Tree(shell, SWT.BORDER | SWT.VIRTUAL | SWT.FULL_SELECTION);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tree.setLinesVisible(true);
tree.setHeaderVisible(true);
final TreeColumn column1 = new TreeColumn(tree, SWT.NONE);
column1.setWidth(75);
column1.setText("Column 1");
final TreeColumn column2 = new TreeColumn(tree, SWT.NONE);
column2.setWidth(75);
column2.setText("Column 2");
final TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText(0, "Hello");
final CCombo combo = new CCombo(tree, SWT.NONE);
combo.setItems(new String[] { "Item 1", "Item 2", "Item 3" });
final TreeEditor editor = new TreeEditor(tree);
editor.setEditor(combo, item, 1);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
// Optional, but allows you to get the current value by calling
// item.getText() instead of going through the TreeEditor and
// calling ((CCombo) editor.getEditor()).getText()
combo.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(final SelectionEvent e) {
item.setText(1, combo.getText());
}
});
}
public void run() {
shell.setSize(200, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public static void main(final String... args) {
new TreeComboBoxTest().run();
}
}
Note the SelectionListener added to the CCombo. Even though you've used the TreeEditor, if you call item.getText(index), it will return an empty String because setText(...) has not been called. By calling setText(...) in the listener, you won't have to go through the TreeEditor to get the value.
So you can call item.getText(index) instead of ((CCombo) editor.getEditor()).getText().
This should be pretty simple but this is the first time I've worked with SWT. This is what I have so far.
public class TabsTest {
private Shell shell;
private CTabFolder folder;
public TabsTest(Display display){
shell = new Shell(display);
shell.setText("TabsTest");
shell.setLayout(new FillLayout());
CTabFolder folder = new CTabFolder(shell, SWT.CLOSE | SWT.BOTTOM);
folder.setUnselectedCloseVisible(false);
folder.setSimple(false);
initUI(folder);
shell.pack();
shell.setBounds(500, 500, 400, 500);
shell.open ();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
}
public void initUI(CTabFolder folder){
CTabItem NFL = new CTabItem(folder, SWT.NONE);
NFL.setText("NFL Bets");
Button okButton = new Button(folder, SWT.PUSH);
okButton.setText("OK");
okButton.setSize(10,10);
NFL.setControl(okButton);
CTabItem NBA = new CTabItem(folder,SWT.NONE);
NBA.setText("NBA Bets");
CTabItem CFB = new CTabItem(folder,SWT.NONE);
CFB.setText("CFB Bets");
folder.setSize(800,500);
}
public static void main (String [] args) {
Display display = new Display();
new TabsTest(display);
display.dispose();
}
}
What this currently gives me is this....
How would I make this a small button in the bottom right corner? Or just in general make it smaller and move it somewhere.
Since you are using a FillLayout the control takes up the entire space available. What you need is a different kind of a layout. I will suggest you to read this article, it will be a good start.
I generally prefer GridLayout as it is quite easy to use and it fulfills most needs.
Edited: Modifying your code to use GridLayout
public class TabsTest {
private Shell shell;
private CTabFolder folder;
public TabsTest(Display display) {
shell = new Shell(display);
shell.setText("TabsTest");
shell.setLayout(new GridLayout());
CTabFolder folder = new CTabFolder(shell, SWT.CLOSE | SWT.BOTTOM);
folder.setUnselectedCloseVisible(false);
folder.setSimple(false);
folder.setLayoutData(new GridData(GridData.FILL_BOTH));
initUI(folder);
shell.pack();
shell.setBounds(500, 500, 400, 500);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public void initUI(CTabFolder folder) {
CTabItem NFL = new CTabItem(folder, SWT.NONE);
NFL.setText("NFL Bets");
Composite nflParent = new Composite(folder, SWT.NONE);
nflParent.setBackground(folder.getDisplay().getSystemColor(SWT.COLOR_BLUE));
nflParent.setLayout(new GridLayout());
Button okButton = new Button(nflParent, SWT.PUSH);
okButton.setText("OK");
GridData gd = new GridData();
gd.verticalAlignment = GridData.END;
gd.horizontalAlignment = GridData.END;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
okButton.setLayoutData(gd);
NFL.setControl(nflParent);
CTabItem NBA = new CTabItem(folder, SWT.NONE);
NBA.setText("NBA Bets");
CTabItem CFB = new CTabItem(folder, SWT.NONE);
CFB.setText("CFB Bets");
folder.setSize(800, 500);
}
public static void main(String[] args) {
Display display = new Display();
new TabsTest(display);
display.dispose();
}
}
The barchart is displayed as small icon on a composite of a view in Eclipse RCP plugin. The chart does not cover the entire composite which should be the actual case. what additional setting needs to be made in code to display the graph on entire composite
Following is the code for displaying the bargraph
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
if(flag == false){
frame.dispose();
}
frame = new ChartComposite(barchartComposite,SWT.NONE,chart,true);
frame.setLayoutData(new GridData(GridData.FILL_BOTH));
frame.setChart(chart);
frame.forceRedraw();
frame.pack();
frame.setVisible(true);
flag= false;
The method createDataset() generates the data for the barchart and method createChart(dataset) generates the barchart.
THE COMPLETE SOURCE CODE FOR DISPLAY OF VIEW
public class BarChartDisplay extends ViewPart {
Text searchfield = null;
String path = SelectDataBase.path;
public static int error=0;
public static int info=0;
public static int critical=0;
public static int warning=0;
ChartComposite frame;
boolean flag=true;
public BarChartDisplay() {
}
#Override
public void createPartControl(Composite parent) {
//Composite A:
final Composite mainComposite = new Composite(parent, SWT.NONE);
GridData mainLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
mainLayoutData.horizontalSpan = 1;
mainComposite.setLayoutData(mainLayoutData);
GridLayout outerLayout = new GridLayout();
outerLayout.marginTop = 30;
outerLayout.marginLeft = 20;
outerLayout.marginRight = 20;
mainComposite.setLayout(new GridLayout(1, false));
//Composite B:
final Composite selectComposite = new Composite(mainComposite, SWT.NONE);
selectComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
selectComposite.setLayout(new GridLayout(4, false));
//Composite C:
final Composite barchartComposite = new Composite(mainComposite, SWT.NONE);
barchartComposite.setLayout(new GridLayout(1, false));
barchartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final CalendarCombo ccombo = new CalendarCombo(selectComposite, SWT.READ_ONLY | SWT.FLAT);
GridData layoutDataCal = new GridData(150, 40);
ccombo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
ccombo.showCalendar();
ccombo.setLayoutData(layoutDataCal);
org.eclipse.swt.widgets.Button button = new org.eclipse.swt.widgets.Button(selectComposite, SWT.PUSH);
button.setText("Go");
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
switch (e.type) {
case SWT.Selection:
error = 0;
info = 0;
warning = 0;
critical = 0;
DB db = new DB();
Connection conn = null;
conn = db.ConnTable(path);
Statement statement;
try {
statement = conn.createStatement();
String query = null;
String textfielddata = ccombo.getDateAsString();
System.out.println(textfielddata);
query = "select priority from log where creation_date = '"+ textfielddata +"'";
System.out.println(query);
ResultSet rs = statement.executeQuery(query);
while (rs.next()) {
int prioritydata = rs.getInt("priority");
if (prioritydata == 1)
error++;
else if (prioritydata == 2)
info++;
else if (prioritydata == 3)
warning++;
else if (prioritydata == 4)
critical++;
}
} catch (SQLException er) {
er.printStackTrace();
}
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
if(flag == false){
frame.dispose();
}
frame = new ChartComposite(barchartComposite,SWT.BORDER,chart,true);
frame.setLayoutData(new GridData(GridData.FILL_BOTH));
frame.setChart(chart);
frame.forceRedraw();
frame.pack();
frame.setVisible(true);
flag= false;
break;
}
}
});
}
/**
* Returns a sample dataset.
*
* #return The dataset.
*/
private CategoryDataset createDataset() {
// row keys...
final String series1 = "First";
// column keys...
final String category1 = "error";
final String category2 = "info";
final String category3 = "warning";
final String category4 = "critical";
// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(error, series1, category1);
dataset.addValue(info, series1, category2);
dataset.addValue(warning, series1, category3);
dataset.addValue(critical, series1, category4);
return dataset;
}
/**
* Creates a sample chart.
*
* #param dataset the dataset.
*
* #return The chart.
*/
private JFreeChart createChart(final CategoryDataset dataset) {
// create the chart...
final JFreeChart chart = ChartFactory.createBarChart(
"Priority BarChart", // chart title
"priority", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips?
false // URLs?
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// set the background color for the chart...
chart.setBackgroundPaint(Color.white);
// get a reference to the plot for further customisation...
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
// set the range axis to display integers only...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// disable bar outlines...
final BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
// set up gradient paints for series...
final GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.blue,
0.0f, 0.0f, Color.lightGray
);
renderer.setSeriesPaint(0, gp0);
final CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
);
// OPTIONAL CUSTOMISATION COMPLETED.
return chart;
}
#Override
public void setFocus() {
}
}
You have to modify the parent composite named barchartComposite.
parent.setLayout(new GridLayout(1, false));
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
Composite barchartComposite = new Composite(parent, SWT.NONE);
barchartComposite.setLayout(new GridLayout(1, false));
barchartComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
ChartComposite frame = new ChartComposite(barchartComposite, SWT.BORDER,chart,true);
frame.setLayoutData(new GridData(GridData.FILL_BOTH));
You have to make sure that barchartcomposite grabs the wohle space of the parent composite. This can be achieved with GridLayout and GridData.
You can find a very useful tutorial about all SWT layouts here:
Understanding Layouts in SWT
I am trying to write a method that will get the current selections from the table and create a ArrayList from the selections.
Method:
public void getPlotterSelection() {
selPrinters = new ArrayList<PrinterProfile>();
int[] row = table.getSelectionIndices();
Arrays.sort(row);
if (row.length > 0) {
for(int i = row.length-1; i >= 0; i--){
PrinterProfile pp = new PrinterProfile(aa.get(i).getPrinterName(), aa.get(i).getProfileName());
selPrinters.add(pp);
}
}
}
This is the error I am getting
ERROR: 16:16:49,503 - TcLogger$IC_LogListener.logging:?
org.eclipse.core.runtime - org.eclipse.ui - 0 - Unhandled event loop exception
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.SWT.error(SWT.java:3770)
at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336)
at org.eclipse.swt.widgets.Table.getSelectionIndices(Table.java:2536)
etc .......
The problem is with this line of code
int[] row = table.getSelectionIndices();
Once again..
I am trying to get the user selected rows in the table and put them in a arraylist.
Edit Adding more code
//////////////////////////////////////////////////////////////////////////
// createDialogArea() //
//////////////////////////////////////////////////////////////////////////
protected Control createDialogArea(Composite parent) {
final Composite area = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.marginWidth = 15;
gridLayout.marginHeight = 10;
area.setLayout(gridLayout);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
area.setLayoutData(gridData);
checkingArray();
createCopyNumber(area);
createPlotterTable(area);
return area;
}
public void checkingArray() {
aa = abd.getPrintersArray();
}
//////////////////////////////////////////////////////////////////////////
// createPlotterTable() //
//////////////////////////////////////////////////////////////////////////
private void createPlotterTable(Composite parent) {
Composite composite = new Composite(parent, SWT.BORDER);
GridLayout gridLayout = new GridLayout(1, false);
composite.setLayout(gridLayout);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
composite.setLayoutData(gridData);
//gridData = new GridData(SWT.FILL, SWT.FILL, true, true );
table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn[] column = new TableColumn[2];
column[0] = new TableColumn(table, SWT.FILL);
column[0].setText("Printer Name");
column[0].setWidth(200);
column[1] = new TableColumn(table, SWT.FILL);
column[1].setText("Profile Name");
column[1].setWidth(200);
gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
table.setLayoutData(gridData);
fillTable(table);
table.setRedraw(true);
}
private void fillTable(Table table) {
table.setRedraw(false);
for(Iterator iterator = abd.getPrintersArray().iterator();iterator.hasNext();){
PrinterProfile printer = (PrinterProfile) iterator.next();
TableItem item = new TableItem(table, SWT.FILL);
int c = 0;
item.setText(c++, printer.getPrinterName());
item.setText(c++, printer.getProfileName());
}
table.setRedraw(true);
}
public void getPlotterSelection() {
selPrinters = new ArrayList<PrinterProfile>();
int[] row = table.getSelectionIndices();
Arrays.sort(row);
if (row.length > 0) {
for(int i = row.length-1; i >= 0; i--){
PrinterProfile pp = new PrinterProfile(aa.get(i).getPrinterName(), aa.get(i).getProfileName());
selPrinters.add(pp);
}
}
}
This is the button that calls the method
Button okButton = createButton(parent, IDialogConstants.OK_ID, "OK", true);
okButton.setEnabled(true);
okButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
getPlotterSelection();
}
});
I would suggest you to user Table viewer rather than Table. It makes your life easier. I see that you are showing table in a dialog. I guess your dialog is getting closed/disposed when you click OK before it get to getPlotterSelection() method.