|
HopePerson wrote: I am stuck With what? You need to give specific details of your problem if you want some useful suggestions.
Use the best guess
|
|
|
|
|
I'm showing or selecting images from a list.
My code for listselectionlistener is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
index = imageList.getSelectedIndex();
imageList.setSelectedIndex(index);
o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));
}
}
};
imageList.addListSelectionListener(listener);
to get next item in JList (imageList) I'm coding like this:
public void nextimage()
{
index ++;
imageList.addListSelectionListener(listener);
imageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
imageList.setSelectedIndex(index); -----here is error: Null Pointer Exception
}
I initialize index as int index=0;
Program in starting returning right value but after 4 or 5 images it's not working.
How can I change the Item in this list?
Please suggest your opinions.
|
|
|
|
|
You need to check if the JList does contain so much values.
You're not coding safe. You need to take more care.
You can never expect a value to be there as you need it - always check if the value is valid before you use it!
|
|
|
|
|
Thanks for your quick reply.
Will you be more specific on checking the value?
As I'm selecting the value from Jlist that is showing thumbnails.
I'm not getting the exact way for selecting next item.
|
|
|
|
|
"TorstenH" want to say you that you have to check the "index" value before using it to set the selected item. You should check "index" value whether it is in the range of your image list size.
Regards
Shubhashish
|
|
|
|
|
Well I did this.
The only problem was SwingUtlities.InvokeLater().
|
|
|
|
|
That's a function, not a problem.
The problem would be that you tried to update the GUI while you where using it.
SwingUtilities.InvokeLater()[^] would cause the Thread to wait and update the GUI when possible.
|
|
|
|
|
How can I perform arrow key event for a GUI in my Java Program?
Thanks!
|
|
|
|
|
|
|
Thanks, all I did was go to the 'K' section in the documentation index.
Use the best guess
|
|
|
|
|
Thanks for your suggestions..
My problem is I want to change the item in a Jlist Programmatically.
That's why I wanted to use this but Robot(AWT key Press Event)not working.
My code is:
listener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Object o = imageList.getSelectedValue();
if (o instanceof BufferedImage) {
imageView.setIcon(new ImageIcon((BufferedImage)o));
}
}
}
imageList.addListSelectionListener(listener);
Well the code is working fine but I want to change the next image using a button or something else
How can I do this?
Please help me in this?
|
|
|
|
|
Sorry, I don't understand the problem. Maybe you need to look at some of the GUI tutorials[^].
Use the best guess
|
|
|
|
|
As "Rechard" suggest, add KeyListener to your imageList and put your logic on KeyPress event to move the next item on the list on up/down arrow key.
Regards
Shubhashish
|
|
|
|
|
Read the tutorial.
and maybe make a little "Area51"-project where you try and test things aside from normal coding.
|
|
|
|
|
Thanks for your suggestions!!!
If I'm not concerning in my project then the main task of mine is to change the
item in a list on an event(Button or String Pass).
...I can do it on press of right key so I thought to read the right key programmatically.
I think you can understand what I want to say..
Thanks!
|
|
|
|
|
Indian Coder1989 wrote: I thought to read the right key programmatically. Yes, and you do this with a KeyListener, as we have said.
Use the best guess
|
|
|
|
|
KeyListener + passing the focus properly:
@Override
public void keyTyped(KeyEvent ke) {
if(ke.getKeyChar() == KeyEvent.VK_LEFT){
}else if(ke.getKeyChar() == KeyEvent.VK_RIGHT){
}
}
@Override
public void keyPressed(KeyEvent e) {
keyTyped(e);
}
also by input mapping:
private void inputMap(){
this.getInputMap().put(KeyStroke.getKeyStroke(
KeyEvent.VK_LEFT, 0), "left");
this.getActionMap().put("left", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent ae) {
}
});
}
|
|
|
|
|
any body knows something about visual midlet?
|
|
|
|
|
|
Hi
How i can use bluetooth in j2me?
i want to connect another device with mobile by bluetooth.
|
|
|
|
|
Hello,
You may want to read following tutorials available on oracle site.
Regards,
Prasad P. Khandekar
Knowledge exists, man only discovers it.
|
|
|
|
|
is it possible to create a fake wifi connection for Android(Something like FakeGPS)?
modified 8-May-13 13:42pm.
|
|
|
|
|
I would suspect it is possible and also rather difficult to do.
|
|
|
|
|
I managed to create a mockup for unit testing.. but I need a dedicated app
|
|
|
|