Cant delete or add item to Jlist as nthing happens
Hi all,
regarding the first part where pass of string array into object array. I have done it (thanks again for the help). But regarding the add and remove elements from the Jlist cant be done.. below is my code for the delete button when press. I cast it into int for the ManualList.getSelectedIndex();(at part A) but cant display and keep having a error call
java.lang.NullPointerException at ManualChange&ValueReporter.valueChanged
code for value reporter is at part B
Part A
private void deleteMouseClicked(MouseEvent e)
int n =(int)ManualList.getSelectedIndex();
if (!(n < 0) || (n > listModel.size()))
listModel.remove(n);
delete.setEnabled(false);
ManualList.repaint();
ManualList.revalidate();
Part B
private class ValueReporter implements ListSelectionListener {
public void valueChanged(ListSelectionEvent event) {
// if (!event.getValueIsAdjusting())
// gettext.setText(ManualList.getSelectedValue().toString());
ManualList.repaint();
ManualList.revalidate();
Any help is greatly appreciated.
alright, i redo part A the code is shown below but i still cant get the display out.
Is there some problem in my code? or is the repaint and revalidate thing wrong usage here ? Need help regarding this. Thanks
int n =ManualList.getSelectedIndex();
if (!(n < 0) || (n > listModel.size()))
listModel.removeElement(arrayObject[n]);
delete.setEnabled(false);
ManualList.repaint();
ManualList.revalidate();
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.MouseEvent.*;
import javax.swing.event.*;
import java.io.*;
import javax.swing.DefaultListModel.*;
import java.util.Properties;
import java.util.ArrayList;
public class smallProgram extends JFrame //implements ListSelectionListener
JPanel p;
private DefaultListModel listModel;
JLabel ManualJob = new JLabel();
JTextField gettext = new JTextField();
JScrollPane scrollPane1 = new JScrollPane();
JButton okButton = new JButton();
JButton cancelButton = new JButton();
JButton add = new JButton();
JButton delete = new JButton();
JList ManualList;
int tokenNo;
String real,ss;
String[] values;
Object[] arrayObject;
java.util.StringTokenizer tokenizer;
BufferedReader in;
ArrayList data;
public static void main(String args[])
new smallProgram();
public smallProgram()
setTitle("Small Program");
p = (JPanel) this.getContentPane();
p.setLayout(null);
setSize(515, 585);
setVisible(true);
//---- ManualJob ----
ManualJob.setText("Manual Jobs Classification");
ManualJob.setFont(new Font("Times New Roman", Font.BOLD, 14));
p.add(ManualJob);
ManualJob.setBounds(10, 435, 190, 35);
setVisible(true);
//---- gettext ----
gettext.setFont(new Font("Times New Roman", Font.PLAIN, 12));
p.add(gettext);
gettext.setBounds(365, 435, 115, 25);
setVisible(true);
//Buttons for add, del, ok and cancel
//---- Add ----
add.setText("Add");
add.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
addMouseClicked(e);
p.add(add);
add.setBounds(355, 485, 60, add.getPreferredSize().height);
//---- delete ----
delete.setText("Delete");
delete.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
deleteMouseClicked(e);
p.add(delete);
delete.setBounds(new Rectangle(new Point(430, 485), delete.getPreferredSize()));
//---- okButton ----
okButton.setText("OK");
okButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
okButtonMouseClicked(e);
p.add(okButton);
okButton.setBounds(335, 520, 75, okButton.getPreferredSize().height);
//---- cancelButton ----
cancelButton.setText("Cancel");
cancelButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
cancelButtonMouseClicked(e);
p.add(cancelButton);
cancelButton.setBounds(420, 520, 75, cancelButton.getPreferredSize().height);
ss = ("test1,test2,test3,test4,test5"); //My string ss
int length = ss.length();
int asd = (ss.indexOf('_'))+1;
real = ss.substring(asd, length);
tokenizer = new java.util.StringTokenizer(real,",");
tokenNo = tokenizer.countTokens();
data = new ArrayList();
values = new String [tokenNo];
// Object[] arrayObject = data.toArray();// this is my initial code where arraylist is pass to object
for(int i =0; i< tokenNo; i++) // pass string-ss into arraylist individually
data.add((tokenizer.nextToken(",")));
//values[i] = tokenizer.nextToken(",");
data.trimToSize();
//System.out.println("tokenizer" + values);
int aaaa = data.size();
System.out.println("size " + aaaa);
System.out.println("tokenizer" + tokenNo);
System.out.println("arraylist "+ i + data.get(i));
//JLIST
//======== scrollPane1 ========
//---- ManualList ---- This is my Jlist // copy arraylist into Object[] then pass it into JList
listModel = new DefaultListModel();
/* listModel = new DefaultListModel(); Part A also continue from above
* for (int i = 0; i< arrayObject.length;i ++)
* listModel.addElement(objectArray[i].toString());
* JList ManualList = new JList(listModel); //tried using listModel.method() to remove item in Jlist but return nullException
arrayObject = data.toArray();
JList ManualList=new JList(arrayObject);
ManualList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ManualList.setSelectedIndex(0);
ManualList.setVisibleRowCount(5);
ManualList.setFont(new Font("Times New Roman", Font.PLAIN,12));
ManualList.setBorder(new MatteBorder(1, 1, 1, 1,Color.black));
ManualList.setLayoutOrientation(JList.VERTICAL_WRAP);
values = new String[tokenNo];
ManualList.addListSelectionListener(new ValueReporter());
// JScrollPane listPanel = new JScrollPane(ManualList);
scrollPane1.setViewportView(ManualList);
p.add(scrollPane1);
scrollPane1.setBounds(210, 435, 130, 75);
setVisible(true);
{ // compute preferred size
Dimension preferredSize = new Dimension();
for(int i = 0; i < p.getComponentCount(); i++) {
Rectangle bounds = p.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width,preferredSize.width);
preferredSize.height = Math.max(bounds.y +bounds.height, preferredSize.height);
Insets insets = p.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
p.setMinimumSize(preferredSize);
p.setPreferredSize(preferredSize);
private void addMouseClicked(MouseEvent e)
private void deleteMouseClicked(MouseEvent e) //nthing happen here
int n =ManualList.getSelectedIndex();
if (!(n < 0) || (n > listModel.size()))
listModel.removeElement(arrayObject[n]);
delete.setEnabled(false);
ManualList.repaint();
ManualList.revalidate();
/* int n =ManualList.getSelectedIndex(); //tried using this but failed
if (!(n < 0) || (n > listModel.size()))
listModel.remove(n);
delete.setEnabled(false);
ManualList.repaint();
ManualList.revalidate();
private void okButtonMouseClicked(MouseEvent e) {
private void cancelButtonMouseClicked(MouseEvent e) {
private class ValueReporter implements ListSelectionListener {
public void valueChanged(ListSelectionEvent event) {
// if (!event.getValueIsAdjusting())
// gettext.setText(ManualList.getSelectedValue().toString());
//String name=(String) ManualList.getSelectedValue();
//System.out.println(name);
private void ManualListMouseClicked(MouseEvent e) {
// int n = (int)ManualList.getSelectedIndex();
// if (!(n < 0) || (n > listModel.size()))
// delete.setEnabled(true);
ok this is a small complete program
Thanks for the time to read this
Similar Messages
-
hi
im a bit confused as to how to add items to a jlist during runtime
could someone please show an exampleHi,
Maybe this will help:
http://www.exampledepot.com/egs/javax.swing/list_ListAddRem.html?l=rel -
How i can add each item to JList. Using loop not use array?
I have not used a JList before, but looking at the API, one of the JLists constructors will take a Vector as one of it's argument
JList API http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JList.html
constructor
JList(Vector listData) so you would be able to add elements to the vector in a loop using the add() method of the vector class
then construct the JList after the elements have been added to the vector, this will mean that you do not have to specify the size of the vector (all thought you can) as it will dynamically grow as you add items to it.
So if you don't know the amount of items that you will be adding to your JList to start with, it is a better bet than using an array
again have a look at the vector API http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html
hope that points you in the right direction
JaVAmUG3380 -
Cant Delete or add users ?
Hi There,
Im running a G5 with 10.5.2 with a basic installation that has not been modified in any way.. all we have really done is set up a sharing folder and added a couple of users. Now for some reason i can add or delete the users anymore...
When i try to delete a user i get this error:
Error '-14120' occurred while processing a command of type 'deleteUser' in plug-in 'servermgr_accounts'
When i try to add a user, i get this error:
The server reported the error '-14120' while trying to create the user.
I have no idea what i can do ? Anyone have a clue ?Hi There,
Im running a G5 with 10.5.2 with a basic installation that has not been modified in any way.. all we have really done is set up a sharing folder and added a couple of users. Now for some reason i can add or delete the users anymore...
When i try to delete a user i get this error:
Error '-14120' occurred while processing a command of type 'deleteUser' in plug-in 'servermgr_accounts'
When i try to add a user, i get this error:
The server reported the error '-14120' while trying to create the user.
I have no idea what i can do ? Anyone have a clue ? -
Probelms Adding items to JList Component
i tried to add items to JList from the database.... and it can add to the variable but the list isnt displaying....
here is my code for that button...
list_ListTopic = new JList(new DefaultListModel());
DefaultListModel listModel = (DefaultListModel)list_ListTopic.getModel();
jScrollPane1 = new JScrollPane(list_ListTopic);
jScrollPane1.setViewportView(list_ListTopic);
Vector data = new Vector();
listModel.clear();
while (lrs.next())
data.add(lrs.getString("tName"));
i++;
list_ListTopic.setListData(data);
jScrollPane1.setViewportView(list_ListTopic);Thanks!Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/list.html]How to Use Lists. It shows you how to initially load data into a list and then how to add/remove entries from the list. In general, you don't update the Vector after the ListModel has been created you update the model directly.
-
hi
i used lov as search... two text item name and age
when i delete the records it cant delete.
my code is
delete_record;
commit;Hi,
delete_record built in, delete the active record from a data block; to remove an element from LOV use DELETE_LIST_ELEMENT instead.
Regards,
Hugo. -
CANT DELETE STARTUP ITEMS FORM PANE!!!
Hi,
I've posted, asked a lot and tried lot of things, but the "Startup Items" window under the accounts pane in Sys Prefs. is now 75 and counting!!! and I'm feeling there's nothing I can do about it!!!
I can't delete the startup items wich all of them read "Extensis Suitcase X1" and "Unknown". Obiously I installed Suitcase and told the app to load at startup, but i feels like auto-duplicates each time I start up the Mac!
I first autenthicate, then select wether one by one or many of them at a time. Click on the "-" button, and nothing! They still remain there like sticked whit cement glue!
Someone could tell me what's next???
Thanks!!Hi, Jota and Richard —
Jota, I don't use Suitcase — and thus can't test solutions — so I'll limit my suggestions.
(1) You may find a specific answer by searching the Extensis KnowledgeBase from this Support web-page. Here are results from a search using terms [login items] — including how to uninstall, problems with multiple accounts, their "Top 5 Troubleshooting Steps" for Mac, etc. I've read through enough of the articles to realize that installing and troubleshooting their software can get pretty complex — so I think following their instructions would be wise...
(2) Have you checked in your HD's /Library/StartupItems/ folder?
(3) I'm not clear on whether you're trying to troubleshoot a problem that may relate to Startup/Login Items. If so, please recall that booting into Safe Mode may help to troubleshoot font, font-cache, and startup-items problems.
Good luck!
Dean
I edited this message... -
I create a new group and an arrow appears next to it (it doesn't have an arrow next to the other groups) and I try and drag events to the group and the events don't get added. I have 7 groups already that are working fine, it is just when I add a new group that the arrow pops up (like it is expandable) and I can't add items to this new group.
Greetings,
Click on the group in question and go to File > New Calendar > On My Mac. Does a new calendar appear?
I create a new group and an arrow appears next to it (it doesn't have an arrow next to the other groups) and I try and drag events to the group and the events don't get added.
Groups do not hold events. They hold calendars. You don't drag events to Groups, you drag Events to calendars.
See if that works. -
Upgraded to leopard and Cant delete podcast in itunes please help
after leopard upgrade.....when i try and delete an old played podcast my itunes immediately pops up an error message and says it quit unexpectedly. this happens w. any podcast and i have the current version of itunes, i also recently upgraded to leopard so i dont know if that has something to do with it, but i CAN play music and videos and podcasts, i just cant delete a podcast, or update them?
any help would be greatGood girl.
"though a bit sluggish" 512 to one gig memory is just making it. two gigs you'll be more satisfied or at minimum 1.5 gigs of memory.
1) I can't answer that based upon normal itunes migration. I just keep my mp3 music on hard drives and when I re-do a computer from scratch just copy them over(they are all metatagged) and use the itunes "add to library" function then change the view using itunes, set my equalizer and I'm basically done.
2) Tiger and Leopard bookmark file are interchangeable. user/library/safari/bookmarks. You should always save that file elsewhere and just drag it over to user/library/safari of course the Safari folder is not created until you launch Safari at least once.
3) use Mail's import function, just direct it to where your mailboxes are stored.
4) address book you can do this function and save it after done. In Tiger under user/library/application support/addressbook there will be a file called addressbook.data Now create a new folder(do it on the desktop) and name it TigerData. Copy that addressbook.data file into that new folder. Now re-name that folder to TigerData.abbu in the addressbook program use the file, import, addressbook archive menu item and choose TigerData.abbu Once done save that file for future Leopard installs. -
The computer insnt letting me update the new itunes. So i deleted it all and now it ses when i try to download a new one that it cant delet the old itunes ... what could i do
Go to Control Panel > Add or Remove Programs (Win XP) or Programs and Features (later)
Remove all of these items in the following order:
iTunes
Apple Software Update
Apple Mobile Device Support (if this won't uninstall move on to the next item)
Bonjour
Apple Application Support
Reboot, download iTunes, then reinstall, either using an account with administrative rights, or right-clicking the downloaded installer and selecting Run as Administrator.
The uninstall and reinstall process will preserve your iTunes library and settings, but ideally you would back up the library and your other important personal documents and data on a regular basis. See this user tip for a suggested technique.
Please note:
Some users may need to follow all the steps in whichever of the following support documents applies to their system. These include some additional manual file and folder deletions not mentioned above.
HT1925: Removing and Reinstalling iTunes for Windows XP
HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
tt2 -
Delete Free Goods Item from Sales Order Return
Hi Gurus!
Could you help me with my question below?
Version 6.0
We created a sales return with reference to a billing document containing a standard item and an inclusive free goods item.
During sales order processing we are trying to delete the free goods item and system does not allow us to do it.
Example:
Item Mat Quant.
10 AAA 10 bx (Standard)
11 AAA 2 bx (Free Goods u2013 Inclusive) -> Try to delete this line.
In our business customer can return any box/quantity and we need this flexibility to create returns with reference to both and one separated item.
Do you know if it is missing any configuration o if there is any Note for this topic?
Tks in advance for you attention.
T.GuimaraesHi,
Free goods is determined automatically in the sales order so you cant delete it manually.
Generally free goods are determined on particular quantity.
Like for every 10quantity you will get 2free.
So if you reduce the quantity of the main item then you free goods will automatically go.
This is the one way in which you can do that.
Other way is that create the new document pricing procedure and assign that one your return document type in VOV8.
Then go to IMG u2013 SD u2013 basic function u2013 free goods u2013 condition technique for free goods u2013 activate free goods determination.
Over here check whether your free goods is activated for the newly created document pricing procedure or not.
If yes then remove that entry and save the setting.
Now create the sales order and check out whether free goods is coming or not.
Please assign the pricing procedure also for your newly created document procedure for your return document otherwise there will be no pricing the return document.
Regards
Raj. -
How do I read txt file and add items to dropdownlist or checkbox
I want to add items to a dropdown or check box by reading from a text file(and select one of them). (I donot use any table or database). The list of items is sometimes upto 20MB and hence cannot populate using session bean.I want items to be added to either checkbox or listbox during a button action. I have done this for textarea but unable so far to acheive for checkbox or listbox. I use following code which does not work:
public String button3_action() {
try{
FileReader fr = new FileReader "F:/CreatorProjects/checkboxtst.prs");
BufferedReader br = new BufferedReader(fr);
String s;
while((s=br.readLine())!=null) {
dropdown1.setValue(s);
br.close();
fr.close();
}catch(Exception e) {
e.printStackTrace();
return null;
I know I cant just transplant textarea code for dropdownlist or checkbox.
Any help is greatly appreciated.
Thanks.
Dr.AM.Mohan RaoI am able to read from txt file to a listbox if i write in sessionsbean1:
try{
FileReader fr = new FileReader("F:/CreatorProjects/checkboxtst.prs");
BufferedReader br = new BufferedReader(fr);
String s1="";
String s="";
while((s=br.readLine())!=null) {
s1 = s1+s;
s1= s1+"\n";
disOptions = new com.sun.rave.web.ui.model.Option[] {
new Option(s1,s1)};
diseases = new String[] {};
fr.close();
br.close();
catch(Exception e) {
e.printStackTrace();
But I get all data in one line!! if I click submit button text area gets all. How to display items in each line????Please help...
Dr.AM. Mohan Rao -
Deletion of Line item in Po after GR occurs
Hi SAP Expert,
Can we make the system to block the users from perform deletion the line item in PO after GR has been made? There are case that the user simpled
delete the line item in PO which GR has been perform and we what to block
the users from do this deletion.Hi,
In attributes of system Message setting for PO try to add message no.06 115 as error and assign the same to users.Moreover this message comes as a standard setting and prevents from deleting the PO line if Gr is made .But this will not restrict if MIRO is done after GR.
Dhruba -
Inserting/ deleting a line item in MIGO Transaction ( Goods Issue )?
Hi,
Can anyone help me with the logic for Inserting / deleting a line item in MIGO Transaction?
Thanks,
csHi
The following user exits and badis for migo:
Check the mb_migo_badi and check the method 'LINE_MODIFY' for u r purpose.
For undestanding see the documentation of the badi and see the example implementation
class: CL_EXM_IM_MB_MIGO_BADI
Enhancement/ Business Add-in Description
Enhancement
MB_CF001 Customer Function Exit in the Case of Updating a Art. Doc.
MBCF0011 Read from RESB and RKPF for print list in MB26
MBCF0010 Customer exit: Create reservation BAPI_RESERVATION_CREATE1
MBCF0009 Filling the storage location field
MBCF0007 Customer function exit: Updating a reservation
MBCF0006 Customer function for WBS element
MBCF0005 Article document item for goods receipt/issue slip
MBCF0002 Customer function exit: Segment text in article doc. item
Business Add-in
MB_RESERVATION_BADI MB21/MB22: Check and Complete Dialog Data
MB_QUAN_CHECK_BADI BAdI: Item Data at Time of Quantity Check
MB_PHYSINV_INTERNAL Connection: Core Inventory and Retail AddOn
MB_MIGO_ITEM_BADI BAdI in MIGO for Changing Item Data
MB_MIGO_BADI BAdI in MIGO for External Detail Subscreens
MB_DOC_BADI_INTERNAL BAdIs when Creating an Article Document (SAP Internal)
MB_DOCUMENT_UPDATE BADI when updating article document: MSEG and MKPF
MB_DOCUMENT_BADI BAdIs when Creating an Article Document
MB_CIN_MM07MFB7_QTY Proposal of quantity from Excise invoice in GR
MB_CIN_MM07MFB7 BAdI for India Version exit in include MM07MFB7
MB_CIN_LMBMBU04 posting of gr
MB_CHECK_LINE_BADI BAdI: Check Line Before Copying to the Blocking Tables
ARC_MM_MATBEL_WRITE Check Add-On-Specific Data for MM_MATBEL
ARC_MM_MATBEL_CHECK Check Add-On-Specific Criteria for MM_MATBEL
If it is helpfu rewards points
Regards
Pratap.M -
I cant delete anything in my itunes as it just crashes
since having itunes match , which im going to let lapse as its pretty useless and constantly loses its info and restores itself! I cant delete any songs or movies without it crashing, i cant even turn it off.
why is it the more apple add the less it works!!!!Hello,
Please open Firefox in Safe Mode and test to see if the the problem still occurs.
See here: [[Troubleshoot Firefox issues using Safe Mode]]
If the issue doesn't occur in Safe Mode then there is a good chance that an Addon or setting is causing the problem. Follow the instructions in the support article above to identify the add-on causing the issue and then disable or remove it.
If the problem still occurs even when opening in safe mode then I suggest doing a Firefox Reset. Again this can be done by holding shift as you open Firefox (select 'Reset' from the options this time).
A reset will return Firefox to its default settings. Your history and bookmarks will be saved but you will need to reinstall your add-ons.
[[Reset Firefox – easily fix most problems]]
I hope that helps.
Maybe you are looking for
-
Error in Delivery using ME2O : "essential transfer parameters are missing"
Hi All We have a subcontracting PO for which when trying to create Delivery using ME2O we are getiing error "essential transfer parameters are missing in record 000001". I understand that this error is coming because shpping point is not ap[earing wh
-
One of my spreadsheets in numbers says it cannot be opened. I am new to numbers so I have not saved anything on iWork or MobileMe but I understood that numbers automatically saves your work as you go. Where can I find that backup? Every other spreads
-
Can I change the default schema from "sql"
I wish to switch between several sets of identical tables under different schemas/owners in the same database - say dev1, dev2, test, prod schemas. The (single) user I connect with (say - called Reader1) has granted select to all these tables, and no
-
Lacking sufficent privilges to make ITUNES the default Audio player.
Never had any problems until updating to this latest version of ITUNES but it now gives me the "you lack sufficent privilages" message whenever I try to set ITUNES as the default player for audio files in preferances. I've set my permissions on MY DO
-
To display combination of single quotes and double quotes in textfield
please send the code