I am working with JavaFX2.0.I need to show the thumbnail images in listview.I am writing the code as below.
ObservableList<BufferedImage> imageList = FXCollections.observableArrayList();
try {
for (int i = 1; i <= pdf.getPageCount(); i++) {
BufferedImage pageImage = pdf.getPageAsImage(i);
imageList.add(pageImage);
} catch (PdfException e) {
_logger.error("Error :" + e.getMessage());
}
thumbnailsList.setItems(imageList);
Here thumbnailsList is the fx:id of the listview.But if i use this code i am getting image object and not an image.Can any one tell me that how can i get the image in listview.
Thank You.
You could use a sample from
http://docs.oracle.com/javafx/2/ui_controls/list-view.htm
which is called "Example 11-4 Creating a Cell Factory".
You have to set custom cell factory. And instead of Rectangle, put an ImageView there.
Related
After GROUP BY, which method can be used for color coding of summary in grid view?
I am able to make changes in color code for value under grid at specific level of record, but for cumulative value, I am having difficulties.
Link for Image
Please find link for image and highlighted part in blue for timestamps for Visit Count row, which need to be color coded.
protected void ASPxGridView1_HtmlDataCellPrepared(object sender,
DevExpress.Web.ASPxGridViewTableDataCellEventArgs e) {
if (e.DataColumn.FieldName != "Budget") return;
if (Convert.ToInt32(e.CellValue) < 100000)
e.Cell.BackColor = System.Drawing.Color.LightCyan;
}
This might help you....
protected void ASPxGridView1_HtmlFooterCellPrepared(object sender, ASPxGridViewTableFooterCellEventArgs e)
{
if (e.Column is GridViewDataColumn )((GridViewDataColumn)e.Column).FieldName == "Freight")
{
e.Cell.ForeColor = Color.Blue;
e.Cell.Font.Bold = true;
}
}
I have two 3d buttons in my scene and when I gaze into any of the buttons it will invoke OnPointerEnter callback and saving the object the pointer gazed to.
Upon pressing Fire1 on the Gamepad I apply materials taken from Resources folder.
My problem started when I gazed into the second button, and pressing Fire1 button will awkwardly changed both buttons at the same time.
This is the script I attached to both of the buttons
using UnityEngine;
using UnityEngine.EventSystems;
using Vuforia;
using System.Collections;
public class TriggerMethods : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
Material _mat;
GameObject targetObject;
Renderer rend;
int i = 0;
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1"))
TukarMat();
}
public void OnPointerEnter(PointerEventData eventData)
{
targetObject = ExecuteEvents.GetEventHandler<IPointerEnterHandler>(eventData.pointerEnter);
}
public void OnPointerExit(PointerEventData eventData)
{
targetObject = null;
}
public void TukarMat()
{
Debug.Log("Value i = " + i);
if (i == 0)
{
ApplyTexture(i);
i++;
}
else if (i == 1)
{
ApplyTexture(i);
i++;
}
else if (i == 2)
{
ApplyTexture(i);
i = 0;
}
}
void ApplyTexture(int i)
{
rend = targetObject.GetComponent<Renderer>();
rend.enabled = true;
switch (i)
{
case 0:
_mat = Resources.Load("Balut", typeof(Material)) as Material;
rend.sharedMaterial = _mat;
break;
case 1:
_mat = Resources.Load("Khasiat", typeof(Material)) as Material;
rend.sharedMaterial = _mat;
break;
case 2:
_mat = Resources.Load("Alma", typeof(Material)) as Material;
rend.sharedMaterial = _mat;
break;
default:
break;
}
}
I sensed some logic error and tried making another class to only manage object the pointer gazed to but I was getting more confused.
Hope getting some helps
Thank you
TukarMat() is beeing called on both buttons when you press Fire1. If targetObject is really becoming null this should give an error on first button since it's trying to get component from a null object. Else, it'll change both as you said. Make sure OnPointerExit is beeing called.
Also, it seems you are changing the shared material.
The documentation suggests:
Modifying sharedMaterial will change the appearance of all objects using this material, and change material settings that are stored in the project too.
It is not recommended to modify materials returned by sharedMaterial. If you want to modify the material of a renderer use material instead.
So, try changing the material property instead of sharedMaterial since it'll change the material for that object only.
I am making a list that has persons and every ones rate as a cell background
the list gives every cell the same rate background but when scroll the list up or down the cell that I'm dragging take it's real rate background but other cells stay the same rate background image
I'm using nokia s40 full touch emulator
This is the code that I'm using for the cell renderer
list.setRenderer(new ListCellRenderer() {
public Component getListFocusComponent(List list) {
// TODO Auto-generated method stub
return null;
}
public Component getListCellRendererComponent(List list,
Object value, int index, boolean isSelected) {
String rate = "";
rate = Transportation.getDriverRate(value.toString(),
CityListForm.selectedCity);
rate = (Integer.parseInt(rate)) > 25 ? "" + 5 : ""
+ Integer.parseInt(rate) / 5;
rate = "/" + rate + ".png";
Image image = null;
Label label = null;
try {
image = (Image.createImage(rate));
System.out.println(rate);
} catch (IOException e) {
e.printStackTrace();
}
label = new Label();
label.getStyle().setBgImage(image);
label.setText(value.toString());
label.getStyle().setAlignment(RIGHT);
label.setTextPosition(RIGHT);
Style style = label.getStyle();
style.setBgColor(16777215);
style.setFgColor(0);
label.setPreferredH(42);
return label;
}
});
Use List.setMutableRendererBackgrounds(true);
thnx for the answer
i solved it by making a container and butting two labels inside it one for the value and the other for the rate icon and give the container a layout and return the container in the getListCellRendererComponent() method
I am developing s60 using j2me with LWUIT in Eclipse.
I am writing this method to draw list item and try to create List manually rather than using Lwuit list. Because as i posted in my last question here is LinK.. don't know why but it decreases performance.
So In below method i trying to create in which i'm adding adding two labels to layoutX Container and adding that Conatiner to layoutY Container and Adding that layoutY to BaseContainer so output is looks like list.
Method is here ...
private void drawAgendasListItem(Vector vector) {
Container containerX[] = new Container[vector.size()];
Container containerY[] = new Container[vector.size()];
if (featuredeventsForm.contains(baseContainer)) {
baseContainer.removeAll();
featuredeventsForm.removeComponent(baseContainer);
System.out.println("base Container is removed ");
}
BoxLayout layoutX = new BoxLayout(BoxLayout.X_AXIS);
BoxLayout layoutY = new BoxLayout(BoxLayout.Y_AXIS);
for (int i = 0; i < vector.size(); i++) {
try {
containerX[i].setLayout(layoutX);
containerY[i].setLayout(layoutY);
Label startTime = new Label();
Label description = new Label();
startTime.getStyle().setBgTransparency(0);
startTime.setText("start 10:20 Am");
startTime.getStyle().setMargin(0, 0, 0, 5);
description.getStyle().setBgTransparency(0);
description.setText("decriptionString");
containerX[i].getStyle().setPadding(0, 0, 2, 2);
containerX[i].addComponent(startTime);
containerX[i].addComponent(description);
containerY[i].addComponent(containerX[i]);
baseContainer.addComponent(i, containerX[i]);
System.out.println("Component added to base Container # " + i);
} catch (Exception e) {
System.out.println("Exception in drawAgendaListItem " + e);
}
}
featuredeventsForm.addComponent(baseContainer);
featuredeventsForm.invalidate();
featuredeventsForm.repaint();
System.out.println("All elements added and form repainted");
}
In above method when i try to assign layout to Container it fires an NullPointerException at line
containerX[i].setLayout(layoutX);.
I don't understand why it's happening, I was also try to comment that lines then it fires NullPointerException at line containerX[i].getStyle().setPadding(0, 0, 2, 2);.
please help ....
Based on the source code, my guess is that you think instantiating an array also populates it. That is not the case in Java.
In other word, if you think that containerX looks like:
[new Container, new Container,..., new Container]
in memory, that is incorrect. It actually looks like:
[null,null,...,null]
I think you need to add
containerX[i] = new Container();
containerY[i] = new Container();
at the beginning of the loop.
(Maybe you want to instantiate the contents of the arrays as subclasses of Container)
I have to display around 100 icons (each 50x50) in Button. I am downloading big png Image which contains all 100 icons, then I create each icon using Image.subImage() method.
But my application getting OutOfMemoryError.
I am thinking about 2 solution for this:
download 100 icons as tar(combined into single) file. So i can
create icon one by one. Big Image need not to be in memory till I
create last icon.
Download big Image but don't create small icon.Then override Button
class to paint image (icon) from big Image.
Which is the best solution? or do you have any other solution for this problem.
LWUIT is designed for small devices, and so should you design your code. So a big image is not a good idea.
You should really use seperate images. and only keep those in memory that you can see. Or you will keep running into outofmemory errors.
I would handle it like this.
Get a cachemap.
if you want an image, check if it isn't already in the cachemap.
if it is, use the image from the cachemap
if it isn't download it and put the image in the cachemap.
when you're out of memory, remove the last image from the cachemap and download the new.
if (imageCache.get(url) != null) {
//#debug
System.out.println("Get cached image from: " + url);
asyncImage.setImage((Image) imageCache.get(url));
asyncImage.setQueued(false);
} else {
//#debug
System.out.println("Start download image from:" + url);
map.put(url, asyncImage);
ImageDownloadService d = new ImageDownloadService(url, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent n = (NetworkEvent) evt;
Image image = (Image) n.getMetaData();
String url = n.getConnectionRequest().getUrl();
AsyncImage asyncImage = (AsyncImage) ImageManager.this.map.get(url);
map.put(url, asyncImage);
asyncImage.setImage(image);
map.remove(url);
imageCache.put(url, asyncImage.getImage());
asyncImage.setQueued(false);
if (Display.getInstance().getCurrent() instanceof AsyncLoadable) {
((AsyncLoadable) Display.getInstance().getCurrent()).asyncLoaded();
} else {
Display.getInstance().getCurrent().repaint();
}
//#debug
System.out.println("Retrieved image from:" + url);
}
});
d.addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent n = (NetworkEvent) evt;
String url = n.getConnectionRequest().getUrl();
AsyncImage asyncImage = (AsyncImage) ImageManager.this.map.get(url);
asyncImage.setQueued(false);
map.remove(n.getConnectionRequest().getUrl());
//#debug
System.out.println("Failed image from:" + url);
}
});
NetworkManager.getInstance().addToQueue(d);