• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

table using lwuit in j2me

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
 
Ranch Hand
Posts: 99
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
vani prahalathan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

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

i need urgently


Please read https://coderanch.com/how-to/java/EaseUp
 
vani prahalathan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone have idea for that error?how can i solved that problem?
help me...
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should be probably
Resources res = Resources.open(getClass().getResourceAsStream("/LwuitImages.res"));
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the directory structure suggested by Maneesh.
 
vani prahalathan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To load the resource them, use

To load an images use
 
vani prahalathan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this



it will work!
 
vani prahalathan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
reply
    Bookmark Topic Watch Topic
  • New Topic