java - 如何使用 LWUIT 居中对齐列表

标签 java java-me lwuit

我在将列表项居中对齐时遇到问题。请帮助我。这是我完成的代码。

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;

import com.sun.lwuit.List;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import javax.microedition.midlet.MIDlet;


/**
 * @author Administrator
 */
public class main extends MIDlet implements ActionListener
{
  private Image logo;
  private Label logoLabel;
  private List menu;
  private Command select,exit;        

  public void startApp() {
    Display.init(this);
    Form form1 =new Form();
    form1.getStyle().setBgColor(0xe5a812);
    try{
        logo=Image.createImage("/sid_logo.png");
    }
    catch(Exception e){
        System.out.println("::::::"+e);
    }
    logoLabel=new Label(logo);
    select=new Command("Select");
    exit=new Command("Exit");

    //form1.setLayout(new BorderLayout());        
    //form1.addComponent(BorderLayout.NORTH,logoLabel);
    BoxLayout boxlayout=new BoxLayout(BoxLayout.Y_AXIS);
    form1.setLayout(boxlayout);
    form1.addComponent(logoLabel);
    logoLabel.setAlignment(Component.CENTER);
    logoLabel.getStyle().setBgColor(0xe5a812);
    menu=new List();
    menu.addItem("LIST 1");
    menu.addItem("LIST 2");
    form1.addComponent(menu);
    form1.addCommand(select);
    form1.addCommand(exit);
    form1.setCommandListener(this);
    form1.show();

  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }
  public void actionPerformed(ActionEvent event){
    //int index=menu.getSelectedIndex();
    if(event.getCommand()==select && menu.getSelectedIndex()==0){
        System.out.println("Check list1");


    }
    if(event.getCommand()==select && menu.getSelectedIndex()==1){
        System.out.println("Check list 2");
    }
    if(event.getCommand()==exit){
        notifyDestroyed();
    }
  }

}

最佳答案

使用list renderer.将该类扩展为Label 并实现ListCellRenderer 接口(interface)。并将Label对齐设置为CENTER

仅供引用:使用ResourceEditor并开发自己的主题。

关于java - 如何使用 LWUIT 居中对齐列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6646693/

相关文章:

java - 使用流从 List<HashMap> 收集键

java - 无法加载 Logmanager "org.jboss.logmanager.LogManager"java.lang.ClassNotFoundException : org. jboss.logmanager.LogManager

iphone - 在移动和 Web 服务器之间同步对象列表的最佳解决方案

java-me - 告诉我这段代码会发生什么?

java-me - JavaME - LWUIT 图像耗尽所有内存

java - arraylist 的副本不断被修改为原始值

java - 如何测试非阻塞 channel 的 SocketChannel.read() 是否已完成?

Java ME : How to wipe all information from a device

java-me - 检查诺基亚设备上是否安装了应用程序?

java - CodeNameOne动态创建的Form,如何 "Back"