Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6566883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:16:10+00:00 2026-05-25T14:16:10+00:00

I’m writing my first LWUIT and Java ME application and trying to get button

  • 0

I’m writing my first LWUIT and Java ME application and trying to get button states to work. I know I can do it in the resource editor, but I’d really like to know why my code isn’t working. The code I have below behaves seemingly erratically. If I select the first button, it works fine. When I select the second button, that button has the foreground of the selected stated, but the background of the unselected state. The same goes for the third button. However, when I wrap back around to the first button, both the first button and the third button have the background of the selected state, the first button has the foreground of the selected state and the third button has the foreground of the unselected state.
I’ve tried reading tutorials and online forums, but it seems that most of those are horribly out of date. Even the tutorial on the official LWUIT page has commands in it that are so deprecated that Netbeans shows them as unresolved instead of deprecated. I’m sure it’s a simple mistake, but I just can’t see from this code how the other buttons should be affected by one getting selected or unselected, or why the style for selected and unselected gets changed every time a buttons state changes.

    Style buttonUp = new Style();
    buttonUp.setAlignment(Component.CENTER);
    buttonUp.setBgColor(0x0082ff);
    buttonUp.setFgColor(0xffffff);
    buttonUp.setMargin(5,5,0,0);

    Style buttonDown = new Style();
    buttonDown.setAlignment(Component.CENTER);
    buttonDown.setBgColor(0xd7d7ee);
    buttonDown.setFgColor(0x000000);
    buttonDown.setMargin(5,5,0,0);        

    Container buttons = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    Button firstButton = new Button("first");
    firstButton.setUnselectedStyle(buttonUp);
    firstButton.setSelectedStyle(buttonDown);
    firstButton.setPressedStyle(buttonDown);

    Button secondButton = new Button("second");
    secondButton.setUnselectedStyle(buttonUp);
    secondButton.setSelectedStyle(buttonDown);
    secondButton.setPressedStyle(buttonDown);

    Button thirdButton = new Button("third");
    thirdButton.setUnselectedStyle(buttonUp);
    thirdButton.setSelectedStyle(buttonDown);
    thirdButton.setPressedStyle(buttonDown);

This should be all of the relevant code as it is the only part that deals with the buttons, other than the addComponent calls that adds the buttons to the container and the container to the form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:16:11+00:00Added an answer on May 25, 2026 at 2:16 pm

    You are reusing style object instances which isn’t legal each component state must have a singular instance. It is more common in LWUIT to do this by:

    button.getUnselectedStyle().setFgColor(...);
    

    Alternatively you can implement the logic in a method:

    updateButtonTheme(Style);
    

    and invoke it as:

    updateButtonTheme(button.getUnselectedStyle());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am writing an app with both english and french support. The app requests
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.