tomas
tomas

Reputation: 739

Designing UI in Kindle KDK (extended java.awt)

I have some experience with Android development and now I have decided to learn something new - developing for Kindle (NOT Android based Kindle Fire).

Amazon offers KDK + Personal Basis Profile 1.1.2 (JSR 217) as a platform.

My problem is, how to design UI. I do not have any experience with awt (just did som apps in java swing), but is doesn't seem to be a big issue, because it's quite simple... Main issue is with 'replacing' android's ListView.

I've tried to use component named KPages. I'm, however, not able to put anything else but KLabel into the pages model...

    PageProvider pp = PageProviders.createKBoxLayoutProvider(KBoxLayout.PAGE_AXIS);
    final KPages pages = new KPages(pp);

    for (int i = 0; i < 40; i++) {
        final KPanel listItem = new KPanel();
        // listItem.add(new KLabelMultiline("label numero " + i + " is not very good, because it will be displayed over more than one line and 'pages' won't be able to deal with it"));
        listItem.add(new KLabel("label numero " + i + " is very good, because it won't be displayed over more than one line and 'pages' will be able to deal with it"));
        listItem.add(new KButton("read"));
        listItem.add(new KButton("edit"));
        pages.addItem(listItem);
    }

    context.getRootContainer().add(pages);

Sample code above shows my effort to list some items. KPages works well only when adding KLabel using pages.addItem(). Just inserting KLabelMultiline causes paging to mulfunction (instead of showing labels 0-12 it 'displays' 0-26 as in single line, but screen of kindle shows only 14-26). Trying to insert whole KPanel with label and 2 buttons results in listing the labels followed by one empty line for each item, without any button... displaying same KPanel outside pages works fine - I can see the label and both buttons...

I'm almost sure it's my fault for leaving something out, but thanks to really little information available on KDK, I'm not able to find it... Can anybody give me a hand? Thanks

Upvotes: 2

Views: 320

Answers (1)

Waynn Lue
Waynn Lue

Reputation: 11375

Try overriding the getPreferredSize, getMinimumSize, and getMaximumSize calls to your constructor for KPanel. Set width and height to whatever your screen size is.

final KPanel listItem = new KPanel() {
  public Dimension getPreferredSize() {
    return new Dimension(width, height);
  }
  public Dimension getMinimumSize() {
    return new Dimension(width, height);
  }
  public Dimension getMaximumSize() {
    return new Dimension(width, height);
  }
};

Upvotes: 0

Related Questions