Two titile bars on a single screen in BlackBerry - blackberry

I am trying to build a screen in BlackBerry. In which there should be a second title bar just below the original title bar. Also the second title bar should be fixed and it should not be scrolled with vertical scroll.
Need some advice on this issue.

You can add the second title and the original title bar on a VerticalFieldManager. Then just set that VerticalFieldManager as title, as it's possible to set any Field, Manager instance as title.
Check public void setTitle(Field title) and following example.
public class DemoScreen extends MainScreen {
public DemoScreen() {
super();
// Prepare a Custom Title
long style = NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR | USE_ALL_WIDTH;
VerticalFieldManager myTitle = new VerticalFieldManager(style);
// Set background color.
myTitle.setBackground(BackgroundFactory.createSolidBackground(Color.GRAY));
// Add any numbers/types of field
myTitle.add(new LabelField("First line."));
myTitle.add(new LabelField("The second line."));
// Set the Title
setTitle(myTitle);
}
}

Related

ExternalResource in Vaadin 10 - Custom Icons for Button

I would like to use a custom icon from a picture file in Vaadin 10.
Up to Vaadin 8 it was possibleto load the icon file via ExternalResource:
public final static Resource MY_ICON = new ExternalResource("VAADIN/images/my_icon.png");
and then just use the resource as icon:
Button button = new Button("My Button text");
button.setIcon(MY_ICON);
The setIcon method in Vaadin 10 requires a Component as parameter. How can i load my Icon into a Component? Is there some out of the box solution in vaadin 10?
I would prefer a solution with pure java like in vaadin 7/8.
I'd recommend putting your icon file as /src/main/webapp/my_icon.png (or /src/main/resources/META-INF/resources/my_icon.png if packaging as a .jar). You can then use it anywhere in your application using the built-in com.vaadin.flow.component.html.Image component, e.g. add(new Image("my_icon.png", "My icon"));.
I will post also my own solution since its specific for Button Icon Styling.
You have to load the icon file into a vaadin Image (com.vaadin.flow.component.html.Image) first. but it also requires some additional styling to position the icon correctly in the button.
import com.vaadin.flow.component.html.Image;
public enum MyIcons {
ICON_1("frontend/img/icon_1.png", ""),
ICON_2("frontend/img/icon_2.png", ""):
private String url;
private String alt;
MyIcons(String url, String alt) {
this.url = url;
this.alt = alt;
}
public Image create() {
Image image = new Image(url, alt);
image.getStyle().set("vertical-align", "middle"); // otherwise the icon will be just on the top left corner in the button
return image;
}
/**
* marign right distance if using Icon in Button with Text. so there is space between the icon and the button text
* #param margin_right
* #return
*/
public Image create(int margin_right) {
Image image = create();
image.getStyle().set("margin-right", margin_right+"px"); //some space between icon and button text
return image;
}
}
usage:
Button button = new Button();
button.setIcon(MyIcons.ICON_1.create());
Button buttonWithText = new Button("My button text");
buttonWithText.setIcon(MyIcons.ICON_1.create(), 10); //10px space between icon and button text

Disable scroll to focused button

Hi a have two buttons at the bottom of the screen and each time I open this screen, view is scrolled to the bottom to show those focused buttons, is there any method to disable this behaviour and firstly display top of the screen?
You have to add a focusable field to the top of your screen. Its up to you how you want to achieve this, but generally you can put a NullField as the first view of your screen.
The NullField should receive the initial focus for you, but note a user can still scroll back to it as with any other view. So it might look like your focus is "lost" depending on how your design looks.
public class MyScreen extends MainScreen
{
public MyScreen()
{
super(VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL);
add(new NullField()); // Nullfield to be initially focused
// Screen content with focusable button at the bottom
add(new LabelField("Label"));
ButtonField button = new ButtonField("Button");
button.setMargin(1000, 0, 0, 0);
add(button);
}
}

create popup screen in blackBerry

I want to create a popup screen in BlackBerry like the screen appear on long click (see the picture)
My screen contain 3 items
image description
image description
image description
Can any one help me by an example or link to do this popup?
Use the below code and call the GetPopup wherever you want to show the pop up screen
final class Getpopup extends PopupScreen
{
EditField edf;
AutoTextEditField edf1;
HorizontalFieldManager hfm;
public Getpopup()
{
super( new VerticalFieldManager());
LabelField lf = new LabelField("Contact Info", LabelField.FIELD_HCENTER);
SeparatorField sf = new SeparatorField();
edf1= new AutoTextEditField("Name:","" ,20,EditField.NO_NEWLINE);
edf = new EditField("Number:",ThirdScreen.get3);
edf.setEditable(false);
VerticalFieldManager vfm =new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
hfm=new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
ButtonField bf1 = new ButtonField("Save", ButtonField.FIELD_HCENTER);
ButtonField bf2 = new ButtonField("Cancel", ButtonField.FIELD_HCENTER);
hfm.add(bf1);
hfm.add(bf2);
vfm.add(lf);
vfm.add(sf);
vfm.add(edf1);
vfm.add(edf);
vfm.add(hfm);
add(vfm);
}
}
Find the code here to create creating-borderless-transparent-popup screen in blackberry
If your looking for custmizing the Buttons as appeared in image then visit custom-image-buttonfield-in-blackberry
You have to make use of GridFieldManager.java for the layout you have used, Also you can customize your own layout.
Create a PopupDialog class which extends Dialog and then in the constructor, add the Buttons. If you would like your buttons to look like the above image, extend a field or button field and in paint method, draw the button and then the button text below the button. Add this custom button control in the PopupDialog.

VAADIN - set full height of tab content

I have a TabSheet and a tab item.
There is a table inside the tab.
I have set all height to setFullSize but the height of the table does not occupy the whole tab.
Code is here:
public class GvApplication extends Application {
private static Logger log = Logger.getLogger(GvApplication.class.getName());
Window mainWindow;
TabSheet tabsheet;
#Override
public void init() {
setTheme("gv");
mainWindow = new Window("Test");
mainWindow.getContent().setHeight("100%");
tabsheet = new TabSheet();
tabsheet.setSizeFull();
mainWindow.addComponent(tabsheet);
initSMSTab();
setMainWindow(mainWindow);
}
private void initSMSTab() {
VerticalLayout tab = new VerticalLayout();
tab.setMargin(true);
Table table = new Table("Naam");
table.setWidth("100%");
table.setHeight("100%");
table.setSizeFull();
tab.addComponent(table);
tabsheet.addTab(tab);
Tab smsTab = tabsheet.getTab(tab);
smsTab.setCaption("SMS");
}
}
There is a lot of space left under the table. How can I make table use the whole content of the tab?
If a component should occupy all the available space in a layout, you have to invoke setExpandRatio on the layout in addition to invoking setSizeFull on the component. In your case:
tabsheet.setSizeFull();
VerticalLayout rootLayout = new VerticalLayout();
rootLayout.setSizeFull();
rootLayout.addComponent(tabsheet);
rootLayout.setExpandRatio(tabsheet, 1f);
mainWindow.setContent(rootLayout);
By default, when you create new table component, table "page length", it mean rows count, value is 15, this is a reason why table do not set full size of your tab. Only way to set full size is increase table "page length" by table.setPageLength(30).
PS. You can remove this lines, because you already use "table.setSizeFull();"
table.setWidth("100%");
table.setHeight("100%");
EDIT 1
Case with you show on your screens in comment will be only when you resize parent or table component. Try fist of all add ResizeListener to your window and inside listener write something like
// This will return current rendered rows count
int shownRowsCount = table.getVisibleItemIds().size();
table.setPageLength(shownRowsCount);

Hide and Collapse menu using Vaadin

Does any one know about how to create hide and collapse content using vaadin api.
All components inherit the setVisible() method which can trigger visibility on and off. This means all components and component containers at least. This happens without animations, though.
If you like some animations, you have to rely to add-ons, e.g. Henrik Paul's Drawer does some kind of hide and show animations.
Is this what you were thinking about?
I achieved it by using TabSheet functionality of vaadin.I created two tabs '+' and '-' whenever user clicks on '-' Tab It am setting the TabSheet height to 100% and whenever the user clicks on the '+' Tab I am setting the height of the TabSheet to 20% (visible height of the tabsheet) so whatever the content in the TabSheet will be hided in user perspective.
// Create an empty tab sheet.
TabSheet tabsheet = new TabSheet();
// Defining Vertical Layout for Tab 1 content
final VerticalLayout verLayout1 = new VerticalLayout();
// Tab 2 content
VerticalLayout verLayout2 = new VerticalLayout();
verLayout2.setSizeUndefined();
verLayout2.setMargin(true);
tabsheet.addTab(verLayout1, "+", null);
tabsheet.addTab(verLayout2, "-", null);
tabsheet.addListener(listenerForTab());
/**
* Method to handle tab sheet hide/show event
*
* #return TabSheet.SelectedTabChangeListener
*/
public TabSheet.SelectedTabChangeListener listenerForTab() {
_logger.info("Entering in to tabChangeListener of WizardUtil");
// Instance of TabSheet.SelectedTabChangeListener
TabSheet.SelectedTabChangeListener listener = new TabSheet.SelectedTabChangeListener() {
public void selectedTabChange(SelectedTabChangeEvent event) {
TabSheet tabsheet = event.getTabSheet();
Tab tab = tabsheet.getTab(tabsheet.getSelectedTab());
// Tab content displayed on setting height to the tab sheet
if(tab.getCaption().equals("+")) {
tabsheet.setHeight("100%");
} else {
tabsheet.setHeight("33px");
}
}
};
_logger.info("Exiting from tabChangeListener of WizardUtil");
return listener;
}

Resources