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();
Related
I'm not sure how to do this:
I have a variable that is passed threw an intent to my new activity.
This variable is a Number. That number received threw the intent will be different depending on the user.
So I want to dynamically write buttons or texViews depending on Number variable.
Example : Number = 4;
There is 4 buttons or textviews (with onclick listener each and text written has Button 1, Button 2, et. ).
Example Number = 10;
There is 10 buttons or textviews or etc. (with onclick listeners each).
Not sure how I can approach this problem
You can create new dynamic views something like that:
Button myButton = new Button(this);
myButton.setText("Push Me");
LinearLayout ll = (LinearLayout)findViewById(R.id.yourLinearLayoutId);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
// with addView method you say to your app when you want to add this view inside on your LinearLayout view
ll.addView(myButton, lp);
In my JavaFX application I use Pagination to show some pictures. Reading the pictures takes much time so I fill an ObservableList<Image> with placeholder images, which should be replaced by the originals when they are loaded.
Everything works fine, but the only thing is that the current page doesn't get updated when the image is loaded. I have to change the CurrentPageIndex and change back. Than the right picture is displayed.
For loading the images I've created a Task, so that I'm able to use the Application during the process.
So my Question is, how is it possible to update the content of the current page?
The PageFactory looks like that:
ImageView imageView = new ImageView();
Image img = images.get(index);
imageView.setImage(img);
imageView.setFitWidth(240);
imageView.setStyle("-fx-background-color: white");
imageView.setPreserveRatio(true);
imageView.setSmooth(true);
imageView.setCache(true);
imageView.setEffect(createShadow(Color.BLACK, false));
VBox pageBox = new VBox();
pageBox.setAlignment(Pos.CENTER);
pageBox.getChildren().add(imageView);
return pageBox;
Here I replace the images (first 2 lines are methods of a framework):
for (int i = 0; i < pageCount; i++) {
PagePainter pp = parser.getPagePainter(i);
BufferedImage buffImg = pp.getImage(200);
fxImages.set(i, SwingFXUtils.toFXImage(buffImg, null));
}
I developed an RSS Application for two XML files and displayed it on two LWUIT Tabs. The problem is with my LWUIT TextArea, whenever I click on my ListForm (it contains titles from the RssFile), I need to display description information from the RSS File. First time I am able to display the description related to the title clicked in ListForm. If I click the ListForm the next time onwards I am able to display the same description again and again in the textarea..(Eventhough I am getting Related Description from RssFile)
Here is my Code:
private void displayCompleteNewsScreen(News detailNews) {
Label title = new Label(detailNews.getTitle());
form2.setTitleComponent(title);
String Description = detailNews.getDescription();
System.out.println("Description" + Description);//Here i am able to get different Description values Related to myList Screen but in text area it is displaying First one always
big = new TextArea();
big.setEditable(false);
big.setText(Description);
form2.addComponent(pubDate);
form2.addComponent(big);
form2.show();
}
As you are reusing form2 instance you should clear it in displayCompleteNewsScreen method. Call removeAll before calling setTitleComponent.
And don't forget to set form2 Commands again in displayCompleteNewsScreen.
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.
I want to align the text in a TextArea to the right. I tried the following code:
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(RIGHT);
form.addComponent(textArea);
The result was just moving the scroll to left,
But the text is still not aligned RIGHT,
check the image below:
So how to align the content to the RIGHT ?
It may sound crazy for the first instance :) but setting the alignment to TextArea.LEFT solved the issue and now it's RIGHT aligned !
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(TextArea.LEFT);
form.addComponent(textArea);
Setting it to LEFT makes the displayed text RIGHT aligned !
Or by removing the textArea.setRTL(true) which is mirroring the display
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setAlignment(TextArea.RIGHT);
form.addComponent(textArea);
For those who are interested in more complicated details when it's set to RTL:
the paint method of TextArea class is
public void paint(Graphics g) {
UIManager.getInstance().getLookAndFeel().drawTextArea(g, this);
}
And drawTextArea method in DefaultLookAndFeel is as follows:
int align = ta.getAbsoluteAlignment();
// remaining code is here in initial source
switch(align) {
case Component.RIGHT:
x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
break;
// remaining code is here in initial source
}
g.drawString(displayText, x, y);
Unfortunately TextArea.RIGHT value is 3
But when calling ta.getAbsoluteAlignment() it returns 1 (despite that the object's alignment is set by code to TextArea.RIGHT !!)
Meanwhile TextArea.Left value is 1
That's why it matched the value in the switch and was aligned to RIGHT
BTW, if you set
textArea.setAlignment(Component.RIGHT);
it will also be wrong, because Component.RIGHT outside the paint method has the value 3 not 1 !
You only have to write 'TextArea.RIGHT' instead of 'RIGHT'
textArea.setAlignment(TextArea.RIGHT);
You can use the following line:
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);