aspose file tools*
The moose likes Java Micro Edition and the fly likes table using lwuit in j2me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "table using lwuit in j2me" Watch "table using lwuit in j2me" New topic
Author

table using lwuit in j2me

vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20



Hi all,

I want to create table/grid using lwuit in tabbedpane.i need urgently for my application..can anybody give me the source code??
i already add some coding for that.but i got some error in defaulttable model...

Here that code and error:

TableModel model = new DefaultTableModel(
new String[] {"Unedit.", "Editable", "Multiline"},
new Object[][] {
{"Row 1", "Data 1", "Multi-line\ndata"},
{"Row 2", "Data 2", "More multi-\nline data"},
{"Row 3", "Data 3", "Data\non\nevery\nline"},
{"Row 4", "Data 4", "Data (no span)"},
{"Row 5", "Data 5", "More data"},
{"Row 6", "Data 6", "More data"},
}) {
public boolean isCellEditable(int row, int col) {
return col != 0;
}
};
Table table = new Table(model);
table.setScrollable(true);
table.setIncludeHeader(true);

// Add table to form and show
f.addComponent(table);


Error:cannot find symbol
symbol : constructor DefaultTableModel(java.lang.String[],java.lang.Object[][])
location: class javax.swing.table.DefaultTableModel
TableModel model = new DefaultTableModel(



Thanks in Advance,
Vani.P
Anuj Prashar
Ranch Hand

Joined: Apr 15, 2008
Posts: 99

As per api


But you using String[] as first and object[][] as second argument and there is no constructor in DefaultTableModel class that takes these parameter in that order and hence error.

Make 2-d object array first argument and use object[] in place in of String[] for second argument in DefaultTableModel constructor.


SCJP 5,SCWCD 5, RHCT
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
Thank you very much its working fine.i got one more error in that table coding.

Error:
cannot find symbol
symbol : constructor Table(javax.swing.table.TableModel)
location: class com.sun.lwuit.table.Table
Table table = new Table(model);
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Welcome to the Ranch.

You should be using the com.sun.lwuit.table.DefaultTableModel and not the Swing version

i need urgently

Please read http://www.coderanch.com/how-to/java/EaseUp

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
Sorry.

i am new one to j2me and this forums.i already import com.sun.lwuit.table.DefaultTableModel ;but the error shown in model.
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
Can anyone have idea for that error?how can i solved that problem?
help me...
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

1) Ensure you have removed the Swing references
2) Ensure you are using the correct constructor arguments

If you still get the error after ensuring the above, copy paste the error here
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
Sorry i cant clear.i do onething ,i just paste my code...can you tell me that what is my mistake?
Code:

TableModel model = new DefaultTableModel(

new Object[][] {
{"Row 1", "Data 1", "123"},
{"Row 2", "Data 2", "1234"},
{"Row 3", "Data 3", "data"},
{"Row 4", "Data 4", "span"},
{"Row 5", "Data 5", "inbox"},
{"Row 6", "Data 6", "forms"},
},
new String[] {"Unedit.", "Editable", "Multiline"}) {
public boolean isCellEditable(int row, int col) {
return col != 0;
}
};
Table table = new Table(model);
table.setScrollable(true);
table.setIncludeHeader(true);

// Add table to form and show
f.addComponent(table);



Container tabcontainer1= new Container();

TabbedPane tp = new TabbedPane();
tp.addTab("Tab 1", new Label("First..........."));
tabcontainer1.getStyle().setBgColor(0x333555);

Error:
cannot find symbol
symbol : constructor Table(javax.swing.table.TableModel)
location: class com.sun.lwuit.table.Table
Table table = new Table(model);
1 error
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Sorry i cant clear....

Huh?
1) Open the relavent .java file
2) Identify all import statements which start with import javax.xxxx
3) Delete all these statements
4) Save file
5) Recompile

Check out the API docs for the com.sun.lwuit.table.DefaultTableModel constructor. The data types of the arguments you are passing, do they match the ones defined in the API?
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
I want to use res file in my application.but there is some error occured.

public Resources getResource() {
Resources resources = null;
try {
resources = Resources.open("/LwuitImages.res");
} catch (IOException io) {
io.printStackTrace();
}
return resources;
}

Error:
java.io.IOException:/LwuitImages.res not found
at com.sun.lwuit.util.Resources.open(Resources.java:456)
at pack.TabMidlet.getResource(TabMidlet.java:131)

i put my .res file (created from resource Editor)into src folder.can you give the solution for that exception?

Thanks in Advance,
Vani.P
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1397
    
    6

It should be probably
Resources res = Resources.open(getClass().getResourceAsStream("/LwuitImages.res"));


Swastik
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

vani prahalathan wrote:
i put my .res file (created from resource Editor)into src folder.can you give the solution for that exception?

The .res file should be under res folder. The res folder should be at the same level as your src folder.
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
Hi,

How are you?I am creating table with tab using lwuit.In my application images are not display..

now i replaced this code.

Resources res = Resources.open(getClass().getResourceAsStream("/LwuitImages.res"));

but i got some error in my application.

where to put res file.i dont know clearly that path.

Thanks
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1397
    
    6

Look at the directory structure suggested by Maneesh.
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
yes.i put res file in res folder and i set the path..

i just paste my code.please tell me the solution.


Code:

public class TabMidlet extends MIDlet implements ActionListener {

Form form = null;
TabbedPane tabpane = null;
private Command cmdExit = new Command("Exit");
//constructor

public TabMidlet() {
//initialize LWUIT
Display.init(this);
}

public void startApp() {
// setTheameRes();
newsTab();
sportsTab();
entertainmentTab();
imageTab();
form.addCommand(cmdExit);
form.addCommandListener(this);
showForm();
}

public void pauseApp() {
/*handle interrupts here*/
}

public void destroyApp(boolean unconditional) {
/*handle uncondition exit from midlet here*/
}

//set the theme
public void setTheameRes() {
Resources r;
try {
r = Resources.open("/LWUITtheme.res");
UIManager.getInstance().setThemeProps(r.getTheme("LWUITDefault"));
} catch (IOException e) {
e.printStackTrace();
}
}


//image tab
public void imageTab() {
tabpane.addTab("Images", new Label(getResource().getImage("lwuitimage")));
}

//news tab
public void newsTab() {
form = new Form();
form.setLayout(new BorderLayout());
form.setScrollable(false);
tabpane = new TabbedPane();
Label label = new Label("NEWS");
label.setText("Headlines of Todays News");
tabpane.addTab("News", label);
}

//entertainment tab
public void entertainmentTab() {
Container panel = new Container(new BorderLayout());
Button button = new Button(getResource().getImage("scenary"));
button.setText("Scenary");
button.setTextPosition(Component.BOTTOM);
panel.addComponent("Center", button);
tabpane.addTab("Entertainment", panel);
}

//sports tab
public void sportsTab() {
Container radioButtonsPanel = new Container(new BoxLayout(BoxLayout.Y_AXIS));
RadioButton topRB = new RadioButton("Cricket");
RadioButton LeftRB = new RadioButton("Football");
RadioButton BottomRB = new RadioButton("Tennis");
RadioButton RightRB = new RadioButton("Hockey");

RadioListener myListener = new RadioListener();
topRB.addActionListener(myListener);
LeftRB.addActionListener(myListener);
BottomRB.addActionListener(myListener);
RightRB.addActionListener(myListener);

ButtonGroup group1 = new ButtonGroup();
group1.add(topRB);
group1.add(LeftRB);
group1.add(BottomRB);
group1.add(RightRB);

radioButtonsPanel.addComponent(new Label("Please choose a tab placement direction:"));
radioButtonsPanel.addComponent(topRB);
radioButtonsPanel.addComponent(LeftRB);
radioButtonsPanel.addComponent(BottomRB);
radioButtonsPanel.addComponent(RightRB);

tabpane.addTab("Sports", radioButtonsPanel);
}

//display form on screen
public void showForm() {
form.addComponent("Center", tabpane);
form.show();
}

//get image from res
public Resources getResource() {
Resources resources = null;
try {
// resources = Resources.open("/LwuitImages.res");
resources = Resources.open(getClass().getResourceAsStream("/res/LwuitImages.res"));
} catch (IOException io) {
io.printStackTrace();
}
return resources;
}

/** Listens to the radio buttons. */
class RadioListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

String title = ((RadioButton) e.getSource()).getText();
if ("Top".equals(title)) {
tabpane.setTabPlacement(TabbedPane.TOP);
} else if ("Left".equals(title)) {
tabpane.setTabPlacement(TabbedPane.LEFT);
} else if ("Bottom".equals(title)) {
tabpane.setTabPlacement(TabbedPane.BOTTOM);
} else {
tabpane.setTabPlacement(TabbedPane.RIGHT);
}
}
}

public void actionPerformed(ActionEvent evt) {
//check which command cliked
if (evt.getCommand() == cmdExit) {
exitMIDlet();
}
}

public void exitMIDlet() {
destroyApp(true);
notifyDestroyed();
}
}

Here there is no image displayed.i have a png file and one res file in res folder near by src folder.please help me
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

To load the resource them, use

To load an images use
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
Yes i am using like this only.
even if single theme is not working..

that is it should not take this resource method.i put res file inside of res folder..
try {
r = Resources.open("/LWUITtheme.res");
UIManager.getInstance().
setThemeProps(r.getTheme("LWUITDefault"));
} catch (IOException e) {
e.printStackTrace();
}

can you give me one theme.res file?
kumar mdu
Ranch Hand

Joined: Jan 04, 2011
Posts: 59
try this



it will work!
vani prahalathan
Greenhorn

Joined: Apr 19, 2011
Posts: 20
i put my res file in res folder near by src folder.i am not having proper res file..

plain white screen is shown in my application .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: table using lwuit in j2me
 
Similar Threads
JTable (Deleting row)
DataTip for a cell in JTable
Jtable Cell and ENTER key
JTable displaying input data onto console
Drag and Drop within the JTable