Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Could any find the error in this piece of code
Could any find the error in this piece of code [message #466362] Mon, 09 January 2006 13:37 Go to next message
Neel is currently offline NeelFriend
Messages: 29
Registered: July 2009
Junior Member
Hi,

In this piece of code, I tried to create a table inside a Group,but this
table is not getting visible when I run it.

Please could any one say wats wrong in this code


// Code Start
package screens;


import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

public class CategorySelectionScr extends Shell {


/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Display display = Display.getDefault();
CategorySelectionScr shell = new CategorySelectionScr(display,
SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Create the shell
* @param display
* @param style
*/
public CategorySelectionScr(Display display, int style) {
super(display, style);
createContents();
}

/**
* Create contents of the window
*/
protected void createContents() {
setText("SWT Application");
setSize(727, 521);

final Composite composite = new Composite(this, SWT.NONE);
composite.setBounds(0, 0, 716, 483);

final Composite composite_1 = new Composite(composite, SWT.NONE);
composite_1.setBounds(5, 25, 214, 455);

final Group selectCategoryGroup = new Group(composite_1, SWT.NONE);
selectCategoryGroup.setText("Select Category");
selectCategoryGroup.setBounds(5, 5, 205, 155);

final CLabel lblcategory = new CLabel(selectCategoryGroup, SWT.NONE);
lblcategory.setAlignment(SWT.RIGHT);
lblcategory.setText("Category");
lblcategory.setBounds(10, 20, 60, 20);

final StyledText styledText = new StyledText(selectCategoryGroup,
SWT.BORDER);
styledText.setBounds(80, 21, 115, 19);

final Button searchButton = new Button(selectCategoryGroup, SWT.NONE);
searchButton.setText("Search");
searchButton.setBounds(110, 55, 90, 30);

final CTabFolder tabFolder = new CTabFolder(composite, SWT.NONE);
tabFolder.setMRUVisible(true);
tabFolder.setBounds(223, 25, 490, 453);

final CTabItem categoryListTabItem = new CTabItem(tabFolder, SWT.NONE);
categoryListTabItem.setText("Category List");

final Group categoryListGroup = new Group(tabFolder, SWT.NONE);
categoryListGroup.setText("Category List");
categoryListTabItem.setControl(categoryListGroup);

final Table table = new Table(categoryListGroup, SWT.BORDER | SWT.RADIO);
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(10, 20, 459, 240);
final TableColumn tc1 = new TableColumn(table, SWT.LEFT);
final TableColumn tc2 = new TableColumn(table, SWT.CENTER);
final TableColumn tc3 = new TableColumn(table, SWT.CENTER);
// final TableColumn tc4 = new TableColumn(table, SWT.CENTER);
tc1.setText("Category");
tc2.setText("Description");
tc3.setText("Slot");
// tc4.setText("Slot");
tc1.setWidth(40);
tc2.setWidth(70);
tc3.setWidth(80);
// tc4.setWidth(70);
final TableItem item1 = new TableItem(table, SWT.NONE);
item1.setText(new String[] { "Radio", "Radio with FM", "Radio" });
final TableItem item2 = new TableItem(table, SWT.NONE);
item2.setText(new String[] { "Fahrersitz", "Fahrersitz", "Fahrersitz"
});





}

//@Override
protected void checkSubclass() {
}

}

// Code Ends


Thanks and Regards,
Neel
Re: Could any find the error in this piece of code [message #466363 is a reply to message #466362] Mon, 09 January 2006 14:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: f.fankhauser.gmx.at

Hi Neel,

class Shell cannot be extended.

From the swt docs for Shell: IMPORTANT: This class is not intended to be
subclassed.

Florian

Neel schrieb:
> Hi,
>
> In this piece of code, I tried to create a table inside a Group,but
> this table is not getting visible when I run it.
>
> Please could any one say wats wrong in this code
>
>
> // Code Start
> package screens;
>
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.CLabel;
> import org.eclipse.swt.custom.CTabFolder;
> import org.eclipse.swt.custom.CTabItem;
> import org.eclipse.swt.custom.StyledText;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Group;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableColumn;
> import org.eclipse.swt.widgets.TableItem;
>
> public class CategorySelectionScr extends Shell {
>
>
> /**
> * Launch the application
> * @param args
> */
> public static void main(String args[]) {
> try {
> Display display = Display.getDefault();
> CategorySelectionScr shell = new
> CategorySelectionScr(display,
> SWT.SHELL_TRIM);
> shell.open();
> shell.layout();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> /**
> * Create the shell
> * @param display
> * @param style
> */
> public CategorySelectionScr(Display display, int style) {
> super(display, style);
> createContents();
> }
>
> /**
> * Create contents of the window
> */
> protected void createContents() {
> setText("SWT Application");
> setSize(727, 521);
>
> final Composite composite = new Composite(this, SWT.NONE);
> composite.setBounds(0, 0, 716, 483);
>
> final Composite composite_1 = new Composite(composite, SWT.NONE);
> composite_1.setBounds(5, 25, 214, 455);
>
> final Group selectCategoryGroup = new Group(composite_1,
> SWT.NONE);
> selectCategoryGroup.setText("Select Category");
> selectCategoryGroup.setBounds(5, 5, 205, 155);
>
> final CLabel lblcategory = new CLabel(selectCategoryGroup,
> SWT.NONE);
> lblcategory.setAlignment(SWT.RIGHT);
> lblcategory.setText("Category");
> lblcategory.setBounds(10, 20, 60, 20);
>
> final StyledText styledText = new
> StyledText(selectCategoryGroup, SWT.BORDER);
> styledText.setBounds(80, 21, 115, 19);
>
> final Button searchButton = new Button(selectCategoryGroup,
> SWT.NONE);
> searchButton.setText("Search");
> searchButton.setBounds(110, 55, 90, 30);
>
> final CTabFolder tabFolder = new CTabFolder(composite, SWT.NONE);
> tabFolder.setMRUVisible(true);
> tabFolder.setBounds(223, 25, 490, 453);
>
> final CTabItem categoryListTabItem = new CTabItem(tabFolder,
> SWT.NONE);
> categoryListTabItem.setText("Category List");
>
> final Group categoryListGroup = new Group(tabFolder, SWT.NONE);
> categoryListGroup.setText("Category List");
> categoryListTabItem.setControl(categoryListGroup);
>
> final Table table = new Table(categoryListGroup, SWT.BORDER |
> SWT.RADIO);
> table.setLinesVisible(true);
> table.setHeaderVisible(true);
> table.setBounds(10, 20, 459, 240);
> final TableColumn tc1 = new TableColumn(table, SWT.LEFT);
> final TableColumn tc2 = new TableColumn(table, SWT.CENTER);
> final TableColumn tc3 = new TableColumn(table, SWT.CENTER);
> // final TableColumn tc4 = new TableColumn(table, SWT.CENTER);
> tc1.setText("Category");
> tc2.setText("Description");
> tc3.setText("Slot");
> // tc4.setText("Slot");
> tc1.setWidth(40);
> tc2.setWidth(70);
> tc3.setWidth(80);
> // tc4.setWidth(70);
> final TableItem item1 = new TableItem(table, SWT.NONE);
> item1.setText(new String[] { "Radio", "Radio with FM", "Radio"
> });
> final TableItem item2 = new TableItem(table, SWT.NONE);
> item2.setText(new String[] { "Fahrersitz", "Fahrersitz",
> "Fahrersitz" });
>
>
>
>
>
> }
>
> //@Override
> protected void checkSubclass() {
> }
>
> }
>
> // Code Ends
>
>
> Thanks and Regards,
> Neel
>
>
>
Re: Could any find the error in this piece of code [message #466366 is a reply to message #466362] Mon, 09 January 2006 14:50 Go to previous messageGo to next message
Daniel Spiewak is currently offline Daniel SpiewakFriend
Messages: 263
Registered: July 2009
Senior Member
Extending Shell doesn't seem to be the issue here. You didn't use any of the non-public API and you properly overrode the checkSubclass() method. I would suggest that you rewrite this so that you extend Composite rather than Shell and then use composition to control the shell instance, but it isn't required for the code to work.

It would seem that you're using absolute positioning (setBounds(int, int, int, int)) rather than a layout manager. I *strongly* advice against this and honestly, I think it's probably your problem. I know that it's possible to do this and many people have, but it's not a good idea. Preferred and minimum sizes vary greatly from platform to platform. You'll find that while this layout may work on Windows, it probably won't work very well on Mac OS X. And while it might work in Bluecurve themed GTK+, it almost certainly won't work if you go to the most recent build of Clearlooks. Try changing the code to use a layout manager and I bet your problem solves itself. :-)
Re: Could any find the error in this piece of code [message #466383 is a reply to message #466362] Mon, 09 January 2006 22:12 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
Call tabFolder.setBounds(223, 25, 490, 453) after calling
categoryListTabItem.setControl(categoryListGroup).


"Neel" <neelakantan_k@infosys.com> wrote in message
news:bfd2ce5b03bef267e1217cc74faae8ff$1@www.eclipse.org...
> Hi,
>
> In this piece of code, I tried to create a table inside a Group,but this
> table is not getting visible when I run it.
>
> Please could any one say wats wrong in this code
>
>
> // Code Start
> package screens;
>
>
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.CLabel;
> import org.eclipse.swt.custom.CTabFolder;
> import org.eclipse.swt.custom.CTabItem;
> import org.eclipse.swt.custom.StyledText;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Group;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableColumn;
> import org.eclipse.swt.widgets.TableItem;
>
> public class CategorySelectionScr extends Shell {
>
>
> /**
> * Launch the application
> * @param args
> */
> public static void main(String args[]) {
> try {
> Display display = Display.getDefault();
> CategorySelectionScr shell = new CategorySelectionScr(display,
> SWT.SHELL_TRIM);
> shell.open();
> shell.layout();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> /**
> * Create the shell
> * @param display
> * @param style
> */
> public CategorySelectionScr(Display display, int style) {
> super(display, style);
> createContents();
> }
>
> /**
> * Create contents of the window
> */
> protected void createContents() {
> setText("SWT Application");
> setSize(727, 521);
>
> final Composite composite = new Composite(this, SWT.NONE);
> composite.setBounds(0, 0, 716, 483);
>
> final Composite composite_1 = new Composite(composite, SWT.NONE);
> composite_1.setBounds(5, 25, 214, 455);
>
> final Group selectCategoryGroup = new Group(composite_1, SWT.NONE);
> selectCategoryGroup.setText("Select Category");
> selectCategoryGroup.setBounds(5, 5, 205, 155);
>
> final CLabel lblcategory = new CLabel(selectCategoryGroup, SWT.NONE);
> lblcategory.setAlignment(SWT.RIGHT);
> lblcategory.setText("Category");
> lblcategory.setBounds(10, 20, 60, 20);
>
> final StyledText styledText = new StyledText(selectCategoryGroup,
> SWT.BORDER);
> styledText.setBounds(80, 21, 115, 19);
>
> final Button searchButton = new Button(selectCategoryGroup, SWT.NONE);
> searchButton.setText("Search");
> searchButton.setBounds(110, 55, 90, 30);
>
> final CTabFolder tabFolder = new CTabFolder(composite, SWT.NONE);
> tabFolder.setMRUVisible(true);
> tabFolder.setBounds(223, 25, 490, 453);
>
> final CTabItem categoryListTabItem = new CTabItem(tabFolder, SWT.NONE);
> categoryListTabItem.setText("Category List");
>
> final Group categoryListGroup = new Group(tabFolder, SWT.NONE);
> categoryListGroup.setText("Category List");
> categoryListTabItem.setControl(categoryListGroup);
>
> final Table table = new Table(categoryListGroup, SWT.BORDER | SWT.RADIO);
> table.setLinesVisible(true);
> table.setHeaderVisible(true);
> table.setBounds(10, 20, 459, 240);
> final TableColumn tc1 = new TableColumn(table, SWT.LEFT);
> final TableColumn tc2 = new TableColumn(table, SWT.CENTER);
> final TableColumn tc3 = new TableColumn(table, SWT.CENTER);
> // final TableColumn tc4 = new TableColumn(table, SWT.CENTER);
> tc1.setText("Category");
> tc2.setText("Description");
> tc3.setText("Slot");
> // tc4.setText("Slot");
> tc1.setWidth(40);
> tc2.setWidth(70);
> tc3.setWidth(80);
> // tc4.setWidth(70);
> final TableItem item1 = new TableItem(table, SWT.NONE);
> item1.setText(new String[] { "Radio", "Radio with FM", "Radio" });
> final TableItem item2 = new TableItem(table, SWT.NONE);
> item2.setText(new String[] { "Fahrersitz", "Fahrersitz",
> "Fahrersitz" });
>
>
>
>
>
> }
>
> //@Override
> protected void checkSubclass() {
> }
>
> }
>
> // Code Ends
>
>
> Thanks and Regards,
> Neel
>
>
>
Previous Topic:Few questions
Next Topic:How to rotate an image?
Goto Forum:
  


Current Time: Fri Apr 19 16:12:21 GMT 2024

Powered by FUDForum. Page generated in 0.01819 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top