I'm working on a J2ME application using LWUIT.
I need to show 10 values with a Label each one.
Something like this:
Label1 Value1
Label2 Value2
Label3 Value3
Label4 Value4
............
LabelN ValueN
I'm using 1 Container for each "row" and one big Container for each "row container"
My problem is with the "rows" outside the screen. The last 4 pairs of Label+value are not showing when I use the scroll
I don't know why.
Can someone solve this?
This is my code:
this.setLayout(new BorderLayout());
PromotionMonitorDTO promotionMonitorDTO = Cloud.getPromotionMonitor();
Utils utils = new Utils();
Font f = Font.getBitmapFont("movSmall");
Container cellContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
Container rowContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
//FIRST PAIR///////////////////////
String stringValue = utils.calendarToShorString(promotionMonitorDTO.getLastUpdate());
Label valor = new Label(LanguageManager.getText("LastUpdate"));
valor.getStyle().setFont(f);
rowContainer.addComponent(valor);
valor = new Label(LanguageManager.getText(stringValue));
valor.getStyle().setFont(f);
rowContainer.addComponent(valor);
cellContainer.addComponent(rowContainer);
rowContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
//SECOND PAIR///////////////////////
stringValue = String.valueOf(promotionMonitorDTO.getInitialTarget());
valor = new Label(LanguageManager.getText("InitialTarget"));
valor.getStyle().setFont(f);
rowContainer.addComponent(valor);
valor = new Label(LanguageManager.getText(stringValue));
valor.getStyle().setFont(f);
rowContainer.addComponent(valor);
cellContainer.addComponent(rowContainer);
////////8 MORE PAIRS////////////////////
this.addComponent(BorderLayout.NORTH, cellContainer);
Finally I solved.
I removed the second Container, I changed the Layout of the form to BoxLayout(BoxLayout.Y_AXIS) and I added all the "row containers" to the form,
With those changes, I have the same Graphic funcionality and the scroll is working.
I have to remove the question? o leave it for others?
Maybe you must "freeze" the Form and make it not scrollable. Set the Form not scrollable using Form.setScrollable(false) and make the center/north Container of your BorderLayoutscrollable. Try to do that.
Related
I want to add nodes into the TitledPane's header. The only way I found to do it is using setGraphic() method.
The problem of using that way is I cannot place them neatly. Here is what I get:
The Codes
TitledPane tpane = new TitledPane();
tpane.setContent(new Text("Content"));
tpane.setExpanded(false);
Button b = new Button("Delete");
BorderPane box = new BorderPane();
box.setLeft(new Text("1 "));
box.setCenter(new Text("Single Pane"));
box.setRight(b);
AnchorPane par = new AnchorPane(box);
tpane.setGraphic(par);
VBox vbox = new VBox();
vbox.getChildren().add(tpane);
The Goal
I want to put the Delete button to the right, that's why I am using Borderpane. So the BorderPane need to fill the entire of the TitledPane's header width minus the space for small triangle
How can it be done inside setGraphic() method? Or are there any better way to achieve it?
To fix your problem try setting the width of the BorderPane to the width of the scene minus the arrow like this.
TitledPane tpane = new TitledPane();
tpane.setContent(new Text("Content"));
tpane.setExpanded(false);
Button b = new Button("Delete");
BorderPane box = new BorderPane();
box.setLeft(new Text("1 "));
box.setCenter(new Text("Single Pane"));
box.setRight(b);
AnchorPane par = new AnchorPane(box);
tpane.setGraphic(par);
VBox vbox = new VBox();
vbox.getChildren().add(tpane);
box.setPrefWidth(scene.getWidth()-30);//You can adjust the number to fit your needs and change scene to whatever the name of your scene is
I hope this helped
Well, it seems that support for javafx users is not as massive as the mainstream framework.
After some tries by the suggestion from #Austin, I found the way to do what I want, and this is also give dynamic sizing.
box.prefWidthProperty().bind(scene.widthProperty().subtract(35));
TitledPane tpane = new TitledPane();
tpane.setContent(new Text("Content"));
tpane.setExpanded(false);
Button b = new Button("Delete");
BorderPane box = new BorderPane();
box.setLeft(new Text("1 "));
box.setCenter(new Text("Single Pane"));
box.setRight(b);
tpane.setGraphic(box);
box.prefWidthProperty().bind(scene.widthProperty().subtract(35));
VBox vbox = new VBox();
vbox.getChildren().add(tpane);
I want text containing integer "expense" will be changed, when "expense" changes itself. But when "expense" variable changes the text continues to display 0. As far as I know it must be solved by binding? How?
int expense=0;
Text expenseAmmount = new Text(String.valueOf(NumberFormat.getIntegerInstance().format(expense)) + " $");
TextFlow moneyStatus = new TextFlow();
TextFlow incomeStatus = new TextFlow();
TextFlow expenseStatus = new TextFlow();
incomeStatus.getChildren().addAll(incomeLabel,incomeAmmount);
expenseStatus.getChildren().addAll(expenseLabel,expenseAmmount);
moneyStatus.getChildren().addAll(moneyLabel,moneyAmmount);
I have found it by myself :
IntegerProperty property = new SimpleIntegerProperty(expense);
expenseAmmount.textProperty().bind(property.asString());
IntegerProperty property = new SimpleIntegerProperty(expense);
expenseAmmount.textProperty().bind(property, new NumberStringConverter());
expenseAmmount.textProperty().bind(property.asString()); was not working for me
I am programmatically creating a text view and trying to place another textView right next to the first one. But I am unable to do it.
Here is the code I have written,
//1st textview
TextView itemText = new TextView(context);
itemText.setText(mItemText);
Typeface itemFont = Typeface.createFromAsset(context.getAssets(), "fonts/" + "Roboto" + ".ttf");
itemText.setTypeface(itemFont,Typeface.BOLD);
itemText.setPadding(0, padding, 0, 0);
itemText.setId(10);
RelativeLayout.LayoutParams itemTextParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
itemTextParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
itemTextParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
itemText.setTextSize(font_size);
itemText.setLayoutParams(itemTextParams);
//2nd text view
TextView seperator = new TextView(context);
seperator.setText(mSeperator);
seperator.setPadding(0,padding,0,0);
seperator.setTypeface(null,Typeface.BOLD);
RelativeLayout.LayoutParams seperatorParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
seperatorParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
seperatorParams.addRule(RelativeLayout.RIGHT_OF,itemText.getId());
seperatorParams.addRule(RelativeLayout.CENTER_VERTICAL);
seperator.setLayoutParams(seperatorParams);
seperatorParams.addRule(RelativeLayout.CENTER_HORIZONTAL) works, but when I use seperatorParams.addRule(RelativeLayout.RIGHT_OF,itemText.getId()) , the text is not shown.
Can anyone point out where I am going wrong? Or is there any other way to do this?
The width of itemTextParams is set to MATCH_PARENT, so there's no space to put anything to the right of it. Change it to WRAP_CONTENT or define a width value.
I've added multiple components to my LWUIT Form one by one,but the problem is i am not able to display those added components one by one as like i appended in my code,i am able to display date and my image on a single row(side by side)some times title and date on a single row,I am getting the details from Rss File.
How to display those components like i added in my code one by one, but not 2 components in a single row?
thanks....
Here my code:
Label pubDate = new Label(detailNews.getPubDate().substring(0, 16));
Label title=new Label();
title.setText(detailNews.getTitle());
title.startTicker();
pubDate.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
Image geImage = detailNews.geImage();
Label icon=new Label(geImage);
form2.addComponent(title);
form2.addComponent(pubDate);
textarea.setText(detailNews.getDescription());
textarea.requestFocus();
form2.addComponent(icon);
form2.addComponent(textarea);
form2.show();
My idea is:
You can create a Container with a BoxLayoutY, and add this TextArea and the icon to the Container. Next, add this Container to the Form. Something like:
Label pubDate = new Label(detailNews.getPubDate().substring(0, 16));
Label title=new Label();
title.setText(detailNews.getTitle());
title.startTicker();
pubDate.getStyle().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL));
Image geImage = detailNews.geImage();
Label icon=new Label(geImage);
Container container = new Container(new BoxLayout(BoxLAyout.Y_AXIS));
container.addComponent(title);
container.addComponent(pubDate);
container.addComponent(icon);
container.addComponent(textarea);
form2.addComponent(container);
textarea.setText(detailNews.getDescription());
textarea.requestFocus();
form2.show();
I want to place a Button in the center of a row of a Container , the Button is the only component of the Container. How to achieve that ?
Container c = new Container(new FlowLayout(Component.CENTER));
Button b = new Button();
c.addComponent(b);
Just set the BorderLayout to Container. Then add the Button into Container and set the constraints to CENTER.
For example,
Container c = new Container(new BorderLayout());
Button btn = new Button("Sample");
c.addComponent(BorderLayout.CENTER, btn);