Skip to main content

LWUIT Custom TitleBar Cannot Scroll or access using D-Pad

1 reply [Last post]
goblooge
Offline
Joined: 2011-06-27
Points: 0

Hello Everyone, i need a help, i want to make the titlebar contains a lot of button and make it scroollable. i done with it, but my problem is :
1. i cannot access the button using D-Pad
2. the scroll appear in titleBar but i cannot move it using D-Pad or Touch it.

Here My Source code that Extends of com.sun.lwuit.Form;
note : i don't want to hide the title bar and make another Container and set it as title bar

Thank's in Advanced and sorry about my bad english, i also attach a file image file that describe about my proble below.

public class Menu extends Form{

public Menu() {
super();

/*Preparing the Title Bar*/
Container c=getTitleArea();
c.removeAll(); // removing the label
c.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
c.setPreferredH(35);
c.setFocusable(true);
c.setEnabled(true);

Container _menu=new Container(new BoxLayout(BoxLayout.X_AXIS));
_menu.setScrollable(true);
_menu.setScrollVisible(true);
_menu.addComponent(new Button("One"));
_menu.addComponent(new Button("Two"));
_menu.addComponent(new Button("Three"));
_menu.addComponent(new Button("Four"));
_menu.addComponent(new Button("Six"));
_menu.addComponent(new Button("Seven"));
c.addComponent(_menu);
}

}

AttachmentSize
problem.png176.61 KB

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
goblooge
Offline
Joined: 2011-06-27
Points: 0

Never Mind, I Found it :D

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package goblooge.toolkid.form;

import com.sun.lwuit.Button;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Form;
import com.sun.lwuit.MenuBar;
import com.sun.lwuit.geom.Dimension;
import com.sun.lwuit.geom.Rectangle;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Style;
import goblooge.toolkid.resource.Resource;

/**
*
* @author goblooge
*/
public class Menu extends Form{

public Menu() {
super();

/*menghapus menu bar*/
MenuBar menubar=this.getMenuBar();
menubar.removeAll();
menubar.setPreferredSize(new Dimension(0, 0));
menubar.setEnabled(false);
menubar.setVisible(false);
menubar.setFocusable(false);

/*Menhapus Title*/
Container c=getTitleArea();
c.removeAll();
c.getStyle().setBackgroundType(Style.BACKGROUND_GRADIENT_LINEAR_VERTICAL);
c.getStyle().setBackgroundGradientStartColor(0x999999);
c.getStyle().setBackgroundGradientEndColor(0x333333);
c.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
c.setPreferredH(35);
c.setEnabled(true);

Container _menu=new Container(new BoxLayout(BoxLayout.X_AXIS));
_menu.setScrollable(true);
_menu.setScrollVisible(false);
_menu.addComponent(new Button("One"));
_menu.addComponent(new Button("Two"));
_menu.addComponent(new Button("Three"));
_menu.addComponent(new Button("Four"));
_menu.addComponent(new Button("Six"));
_menu.addComponent(new Button("Seven"));

addComponent(new Button("hooda"));

c.addComponent(_menu);

getContentPane().getStyle().setBgImage(Resource.BACKGROUND);
getContentPane().getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_TILE_BOTH);
getContentPane().setSize(new Dimension(Resource.LEBAR, Resource.TINGGI));
setLayout(new BoxLayout(BoxLayout.Y_AXIS));

}

public void pointerDragged(int x, int y) {
super.pointerDragged(x, y);
Component cmp = getTitleArea().getComponentAt(x, y);
if (cmp != null) {
if (cmp.isFocusable() && cmp.isEnabled()) {
setFocused(cmp);
}
cmp.pointerDragged(x, y);
cmp.repaint();
}
}

public void pointerPressed(int x, int y) {
super.pointerPressed(x, y);
Component cmp = getTitleArea().getComponentAt(x, y);
if(cmp!=null) cmp.requestFocus();
}

public void keyPressed(int keyCode) {
super.keyPressed(keyCode);
}

public Component findNextFocusHorizontal(boolean right) {
Component c=super.findNextFocusHorizontal(right);
if(c==null){
c = findNextFocusHorizontal(getFocused(), null, getTitleArea(), right);
if(c != null) {
return c;
}
if(isCyclicFocus()) {
c = findNextFocusHorizontal(getFocused(), null, getTitleArea(), !right);
if(c != null) {
Component current = findNextFocusHorizontal(c, null, getTitleArea(), !right);
while(current != null) {
c = current;
current = findNextFocusHorizontal(c, null, getTitleArea(), !right);
}
return c;
}
return null;
}
}
return c;
}

public Component findNextFocusVertical(boolean down) {
Component c= super.findNextFocusVertical(down);

if(c==null){
c = findNextFocusVertical(getFocused(), null, getTitleArea(), down);
if(c != null) {
return c;
}
if(isCyclicFocus()) {
c = findNextFocusVertical(getFocused(), null, getTitleArea(), !down);
if(c != null) {
Component current = findNextFocusVertical(c, null, getTitleArea(), !down);
while(current != null) {
c = current;
current = findNextFocusVertical(c, null, getTitleArea(), !down);
}
return c;
}
}
return null;

}
return c;

}

private Component findNextFocusVertical(Component focused, Component bestCandidate, Container root, boolean down) {
int count = root.getComponentCount();
for(int iter = 0 ; iter < count ; iter++) {
Component current = root.getComponentAt(iter);
if(current.isFocusable()) {
int currentY = current.getAbsoluteY();
int focusedY = focused.getAbsoluteY();
if(down) {
if(focusedY < currentY) {
if(bestCandidate != null) {
boolean exitingInSame = isInSameColumn(focused, bestCandidate);
if(bestCandidate.getAbsoluteY() < currentY) {
if(exitingInSame) {
continue;
}
if(isInSameRow(current, bestCandidate) && !isInSameColumn(focused, current)) {
continue;
}
}
if(exitingInSame && isInSameRow(current, bestCandidate)) {
continue;
}
}
bestCandidate = current;
}
} else {
if(focusedY > currentY) {
if(bestCandidate != null) {
boolean exitingInSame = isInSameColumn(focused, bestCandidate);
if(bestCandidate.getAbsoluteY() > currentY) {
if(exitingInSame) {
continue;
}
if(isInSameRow(current, bestCandidate) && !isInSameColumn(focused, current)) {
continue;
}
}
if(exitingInSame && isInSameRow(current, bestCandidate)) {
continue;
}
}
bestCandidate = current;
}
}
}
if(current instanceof Container && !(((Container)current).isFocusable())) {
bestCandidate = findNextFocusVertical(focused, bestCandidate, (Container)current, down);
}
}
return bestCandidate;
}

private boolean isInSameColumn(Component source, Component dest) {
return Rectangle.intersects(source.getAbsoluteX(), 0,
source.getWidth(), Integer.MAX_VALUE, dest.getAbsoluteX(), dest.getAbsoluteY(),
dest.getWidth(), dest.getHeight());
}

private boolean isInSameRow(Component source, Component dest) {
return Rectangle.intersects(0, source.getAbsoluteY(),
Integer.MAX_VALUE, source.getHeight(), dest.getAbsoluteX(), dest.getAbsoluteY(),
dest.getWidth(), dest.getHeight());
}

private Component findNextFocusHorizontal(Component focused, Component bestCandidate, Container root, boolean right) {
int count = root.getComponentCount();
for(int iter = 0 ; iter < count ; iter++) {
Component current = root.getComponentAt(iter);
if(current.isFocusable()) {
if(isInSameRow(focused, current)) {
int currentX = current.getAbsoluteX();
int focusedX = focused.getAbsoluteX();
if(right) {
if(focusedX < currentX) {
if(bestCandidate != null) {
if(bestCandidate.getAbsoluteX() < currentX) {
continue;
}
}
bestCandidate = current;
}
} else {
if(focusedX > currentX) {
if(bestCandidate != null) {
if(bestCandidate.getAbsoluteX() > currentX) {
continue;
}
}
bestCandidate = current;
}
}
}
}
if(current instanceof Container && !(((Container)current).isFocusable())) {
bestCandidate = findNextFocusHorizontal(focused, bestCandidate, (Container)current, right);
}
}
return bestCandidate;
}

}