How to add contents of an arrayList to a JList
Hi,
I am trying to figure out how to add the contents of an arraylist to a Jlist.
Basically I have 3 classes which are as follow:
1. AuctionItems(String name, int bid) which represents an item in auction
2. AuctionItemsFactory which creates AuctionItems and adds them to an arraylist called stock
3. AuctionBidsGui1 which is the interface where the user can see the items in the auction and select them from a JList.
But I dont know how to read the contents of the stock(arraylist) into the JList which is in AuctionBidsGui1. Below are the 3 classes mentioned above
public class AuctionItems {
String name;
int bid;
public AuctionItems(){
name = null;
bid = 0;
public AuctionItems(String name, int bid){
this.name = name;
this.bid = bid;
public String getName(){
return name;
public int getBid() {
return bid;
public class AuctionItemsFactory {
private ArrayList<AuctionItems> stock;
int size;
public AuctionItemsFactory() {
stock = new ArrayList<AuctionItems>();
public void addItems(AuctionItems item) {
stock.add(item);
//removes last element of the arrayList
public void removeItems() {
int n = stock.size() - 1;
stock.remove(n);
public void printNumOfItems() {
int n = stock.size();
System.out.println(n);
public int numberOfItems(){
return stock.size();
public void printItems(){
for (AuctionItems item : stock) System.out.println(item);
and this one is a small part of the AuctionBidsGui1 class which represents the JList where the list of the items will go.
public void addItemListWidgets() {
itemsList = new JList();
itemsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
itemsList.setLayoutOrientation(JList.VERTICAL);
itemsList.setVisibleRowCount(10);
itemsList.setSelectedIndex(0);
JScrollPane itemsListScroller = new JScrollPane(itemsList); // put the list in the scroller
itemsListScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
itemsListScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
itemsListPanel.add(itemsListScroller);
}
I know that I have to use the toArray() but i dont know what type of method to use for this because i will need to implement a method in my AuctionItemsFactory class which will copy the contents of the arraylist into an array so then i can call this methos from my AuctionBidGui1 class.
I would appreciate if you could give me a bit more hints.
Similar Messages
-
How to add content source in office 365 ?
How to add content source in office 365 , where I can add find Manage Content Sources page to click on New Content Source LInk
You can't. Only sources available is what is already set up...which is SharePoint/OneDrive4B and Exchange via eDiscovery.
Thanks,
Mikael Svenson - Search Enthusiast
SharePoint MVP/MCPD/P-TSP - If you find an answer useful, please up-vote it.
http://techmikael.blogspot.com/
Author of
SharePoint Search Queries Explained and
Working with FAST Search Server 2010 for SharePoint -
How to write contents of an ArrayList to JTable
I have an ArrayList named 'innercell'. It contains the following contents
cs123, 0.34567
cs234, 0.5673
cs234,cs456, 0.5674
this arraylist is added to another arraylist 'cells'
cells.add(innercell);
now the contents of the 'cells' arraylist is
cs123, 0.34567
cs234, 0.5673
cs234,cs456, 0.5674
i have created a JTable and its variable name is 'jtable' (object) (*i'm using NetBeans IDE 6.0*)
and the model of this JTable is as below (it is the generated code by NetBeans IDE 6.0)
jtable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null}
new String [] {
"Title 1", "Title 2"
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
i have only 2 columns in the table, and 9 rows
now i want 2 place contents of 'cells' arraylist to JTable as below
Tittle 1 Title 2
cs123 0.34567
cs234 0.5673
cs234,cs456 0.5674
to write in this form i'm using following code
String[] columnNames={"Title 1","Title 2"};
Object[][] rowdata=new Object[9][2];
str=items;//items is the string value.the possible 'items' values {cs123,...}
sup=value;//value is the double value. the possible 'value' are {0.5674,......}.i'm not given how i'm geting these values
for(int k=0;k<2;k++){
if(k==0)
rowdata[i][k]=str;
else
rowdata[i][k]=sup;
jtable=new JTable(rowdata,columnNames);//is this statement is right to add the contents of arraylist to the table?
jtable.setVisible(true);
but it is not working....i'm getting "NullPointerException"Swing related questions should be posted in the Swing forum.
Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.
Don't use an IDE to generate your code. Learn how to write your own code. Its hard enough to learn how to use Java without learning how to use the IDE as well.
Use the DefaultTableModel. You can build the model using Vectors or Arrays or by adding individuals rows of data to the model. There is no need to create a custom TableModel. -
How to Add Content Editor WebPart in PageLayout
Hi
I have copied the Content Editor webpart snippet and pasted it in my Page layout.
But nothing is showing in page edit mode.
Can anyone tell me how to add this if the following is not correct?
<div style="width:100%">
<div data-name="WebPartZone">
<!--CS: Start Content Editor Snippet--><!--SPM:<%@Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint,
Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>--><!--MS:<WebPartPages:ContentEditorWebPart xmlns:WebPartPages="namespace" runat="server" webpart="true">--><!--PS: Start of READ-ONLY
PREVIEW (do not modify)--><div class="ms-webpart-chrome ms-webpart-chrome-fullWidth "><div class="ms-webpart-chrome-title" id="WebPart_ChromeTitle"><span title="$Resources:core,ContentEditorWebPartTitle;
- $Resources:core,ContentEditorWebPartDescription;" id="WebPartTitle" class="js-webpart-titleCell"><h2 style="text-align:justify;" class="ms-webpart-titleText"><nobr><span>$Resources:core,ContentEditorWebPartTitle;</span><span
id="WebPartCaption"></span></nobr></h2></span></div><div WebPartID="00000000-0000-0000-0000-000000000000" HasPers="true" id="WebPart" width="100%" class="ms-WPBody ms-WPBorder
noindex ms-wpContentDivSpace " OnlyForMePart="true" allowDelete="false" style=""><div class="ms-rtestate-field"></div><div class="ms-clear"></div></div></div><!--PE:
End of READ-ONLY PREVIEW--><!--MS:<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">--><!--MS:<Title>--><!--SPM:$Resources:core,ContentEditorWebPartTitle;--><!--ME:</Title>--><!--MS:<Description>--><!--SPM:$Resources:core,ContentEditorWebPartDescription;--><!--ME:</Description>--><!--MS:<PartImageLarge>--><!--SPM:/_layouts/15/images/mscontl.gif--><!--ME:</PartImageLarge>--><!--MS:<ID>--><!--SPM:g_4998626c_cd3f_4f31_962c_51e943923c4f--><!--ME:</ID>--><!--ME:</WebPart>--><!--ME:</WebPartPages:ContentEditorWebPart>--><!--CE:
End Content Editor Snippet-->
</div>
</div>
S H A J A NHi ,
For adding the Content Editor Web Part to a SharePoint Layout , you can add the code between the <Zonetemplate> tags:
<!-- CEWP -->
<WebPartPages:ContentEditorWebPart ID="ContentEditorWebPart1" runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{F40E10C3-ED3A-473D-8538-996344EE795C}" >
<WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Content Editor Web Part</Title>
<FrameType>TitleBarOnly</FrameType>
<Description>Use for formatted text, tables, and images.</Description>
<IsIncluded>true</IsIncluded>
<PartOrder>2</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>true</AllowConnect>
<AllowEdit>true</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
<IsIncludedFilter />
<ExportControlledProperties>true</ExportControlledProperties>
<ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID>
<ID>g_f40e10c3_ed3a_473d_8538_996344ee795c</ID>
<ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
<Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor"><![CDATA[Edit this text.]]></Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
</WebPartPages:ContentEditorWebPart>
For more information, you can refer to the thread:
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/1ba645f2-2481-4560-a4c3-3be9f9e878bc/adding-the-content-editor-web-part-to-a-sharepoint-layout-aspx-page?forum=sharepointcustomizationlegacy
http://hiren-j-patel.blogspot.com/2012/07/hello-all-today-we-will-add-content.html
Best Regards,
Eric
Eric Tao
TechNet Community Support -
How to add Content workflow to Webcenter spaces/ custom application
I would like to add Content work-flows ( Add - review - publish of content) to Webcenter spaces.so that users of Spaces/ application can work with add- publish-review cycle. I want to know if any thing like portlet or something available that can be added.
I have a webcenter 11g associated with OCS 10.1.3. Does the suites Content Portlet Suite/Content Integration Suite contain these workflows? Please help me in this regard thanks.
Thanks,
indra.Yes. it is the same way. once the Portletsuite is integrated you can create a workflow in Oracle conent server using Workflow Manager Applet. Extenal Identity store needs to be configured.
But I have some problem with webcenter spaces users on external Ldap server. In contribution checkout step ,I am not getting the checkout link. i am getting exception like "not suffient privilage".
But the workflow seems to work fine in idc application.
Unable to get schema fields. User 'auser' does not have sufficient privileges
* !csUserEventMessage,auser,CIS!$!csSchErrorGettingFields!csUserInsufficientAccess,auser
intradoc.common.ServiceException: !csSchErrorGettingFields!csUserInsufficientAccess,auser
at intradoc.server.ServiceRequestImplementor.buildServiceException(ServiceRequestImplementor*
I created Users in webspaces using Own Registration feature. User gets created on Ldap server. And I am able to log on to the content server. If anybody happend to know more on this ,please reply.
Edited by: indra_owc on Dec 21, 2009 7:03 PM -
How to add contents of hashset to file?
guys, i need to write hashset data to file..
here is my code:
HashSet<String> hs = new HashSet<String>();
File outfile3= new File("C:\\test.txt");
FileWriter of3 = (new FileWriter(outfile3));
Iterator it = hs.iterator();
while (it.hasNext()) {
String t = it.next(); <=error
of3.write(t);
error : Type mismatch: cannot convert from Object to String
help me out guys..
thanx in advance..add contents of hashset to file
... write hashset data to file
... new FileWriter(outfile3)Is it write or append? If append: I think FileWriter accepts an optional boolean append parameter.
of3.write(t);Try this:
of3.write(String.valueOf(t));... and BTW "wrapping" your FileWriter in a BufferedWriter improves throughput.
Cheers. Keith. -
How to add contents to Tab in TabStrip
Hi All,
My requirement is to display a screen/view as a content to a TAB when user selects any tab in the Tab Strip. I have developed screens for each tab seperately.
Can any one tell me how to achieve this in web dynpro.
Many Thanks.
Regs/Venkathi
>First insert tabstrip ui
>Right click tab strip ui and select insert Tab
>Expand the Tab and select the Tabs_content and right click the tab content and select insert child and select the ViewContainerUIElement
>In the Web dynpro Explorer View,expand the Project structure and select the Windows in the components.In the windows select ur window and expand it.
where u can see the view container you have inserted in the tab
>select the view containeruielement and right click it and select the Embed view and select the view which you want to embed
hope this helps,
Regards,
Arun -
How to add two sets of arraylists together into one?
Hi there
I am trying to finish my assignment for a car dealer..
welll i have got two arrays in my Dealaership Class
I did something like
ArrayList customerSoldCars;
ArrayList customerBotCars;
I was wondering if it's possible to add them together as in something like
ArrayList allCustomer = customerSoldCars + customerBotCars;
so that i can just create a method something called listAllCustomers()
which will be showing the list of both "customers who sold the their cars to the dealer" and "customers who bot the cars from the dealer"
any help would b highly appriciated..
cheerzYou can use a Set (in order to avoid duplicates.)
Then you simply add your lists' customers to the set using the addAll method.
This way, you will obtain all your customers from the two lists merged into a single collection.
Finally, if you really need a List, you can create one out of the Set. -
Need Help, Don't Know How To Add Content
www.collegiateboard.com/main.html
I want to add text or an image below the sidebar1 (below, Click the Demo link if you want to mess around before posting)
Is there a way to add text there but I want it to be kept white. Meaning I don't want to extend the grey box lower. I want the grey box to stop there and add new text in the white area below it.
I would appreciate it if anyone can help me.This forum is for questions regarding HTML5 (a new web specification).
For general HTML or CSS layout questions, please visit the Dreamweaver General Discussion forum (see link below).
http://forums.adobe.com/thread/793650?tstart=0
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media Specialists
http://alt-web.com/
http://twitter.com/altweb -
How to Add content like on ie8 mymsn? The fox new groups and sports group from fox
On mymsn in ie8 I can have different sites such as fox news grettawire fox golf news, NFL news, NASCAR news, PC mag and many others. I would like to try firefox but do not know how to customize it.
Hi,
SEM-BCS or BI-BPC NW 7.0N is meant for similar kind of requirements. You'll probably need to get a functional guy involved for mapping the GL accounts from the new company to your existing one and have journal entries for inter-company transactions. After doing the same you can then consolidate both the data and have a common output.
search about BPC or BCS and you'll find out more. If you still need to do it in existing BI setup then get someone from FI and set the mappings of GL Accounts from both set the business rules and create a new cube to load the consolidated data.
Hope this helps
Regards
Raj -
How to add words from a JTextField to a JList
Im working on my final project for Java programming class using JApplet.
Im trying to create a spelling test/wordfind
I want to be able to have the user type a word in the JtextField press the "Add" button (Jbutton) and have the word be added to the JList.
then click the "Start" Button and have the all the words from the JList be put in random stops in a panel and fill around all the words with random letters.
then when the user clicks on the letter of the words they are finding it will change colors if they click on it again it will change back to its original color.
So far I have my layout set up its adding the proper Listeners and events to achieve the desired results.
I know this is way more advanced than what My Instructor is even teacher but I am very interested in Java and want to learn a lot more about it.
If anyone has suggestions or know where i can find the information Im looking for please let me know.
Thanks
Code I have so Far:
* @(#)SpellingTest.java
* SpellingTest Applet application
* @author
* @version 1.00 2010/11/10
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SpellingTest extends JApplet implements ActionListener {
Image img;
ImageIcon icon;
private Image title;
JTextField word;
JButton addWord;
JLabel label;
JList wordList;
public void init() {//opening init
getContentPane().setLayout(null);
getContentPane().setBackground(Color.WHITE);
title = getImage(getDocumentBase(), "title.jpg");
//The text field
word = new JTextField();
word.setLocation(190,100);
word.setSize(85,30);
getContentPane().add(word);
word.addActionListener(this);
//The addWord button
addWord = new JButton("ADD");
addWord.setLocation(295, 100);
addWord.setSize(90,30);
getContentPane().add(addWord);
addWord.setBackground(new Color(146, 205, 220));
addWord.addActionListener(this);
//The label
label = new JLabel("Type your spelling words:");
label.setLocation(25, 65);
label.setSize(250,100);
getContentPane().add(label);
label.setForeground(new Color(146, 205, 220));
//The List
wordList = new JList();
JScrollPane scrollPane = new JScrollPane(wordList,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setLocation(25,150);
scrollPane.setSize(150,300);
getContentPane().add(scrollPane);
}//closing init
public void actionPerformed (ActionEvent ae){
Object obj = ae.getSource();
String text = word.getText();
if (obj == addWord){
if (text.length()>0);
wordList.addString("");
public void paint(Graphics g) {
super.paint(g);
}Read the first posting titled "Welcome to the new home" to learn how to use code tags. Then you can edit your posting so the code is formatted and readable.
I want to be able to have the user type a word in the JtextField press the "Add" button (Jbutton) and have the word be added to the JList.Read the JList API and follow the link to the Swing tutoral on "How to Use Lists" where you will find a working example.
So far I have my layout Actually you haven't. You should learn how to use layout managers. Again the Swing tutorial explains what layout managers are and provides working example of using them.
I am very interested in Java and want to learn a lot more about it.A great place to start is by read tutorials because they always contain working example. Here are some [url http://download.oracle.com/javase/tutorial/]Java tutorrial. -
How to add styles to the content on the screen
Hi All
I am able to dispaly the content of a .txt file on the screen using inline frames(11g adf using content repository- file system) . But 'm able to add styles to it like displaying it in bold letters. Any help on how to add templates
Link which i followed http://download.oracle.com/docs/cd/E12839_01/webcenter.1111/e10148/jpsdg_content.htm
8.3.1 How to Add Content as an ADF Inline Frame
code
<af:inlineFrame id="inlineFrame1"
source="/content/conn/Test/path/test1/Test.txt"
inlineStyle="height:100px; color:Aqua;"
styleClass="AFStretchWidth">
</af:inlineFrame>
Thanks,
Tim.
Edited by: 831631 on Feb 16, 2011 11:00 PMhi Tim
831631 wrote:
Yes.
• Consider a file Sample.txt file contains the text – “Hello World. Welcome”
• Display “Hello World” in bold and display “Welcome” underlinedI don't think that adding style to a plain text file (as such) will be possible, you should probably use HTML or another document format.
success
Jan -
How to configure content presenter taskflow parameters both design time
Hi,
I want to add content presenter taskflow to my portal page and want to configure taskflow parameters at both design and runtime?
So would like to know how to add content presenter taskflow(not content) to my portal page and how to configure parameters at both design and runtime?Hi Yannick,
Going through the links which you have provided and will come back to you I face any problem.
Before going through the link I would like to know how to get content from ucms from specifying a query rather than getting from the entire folder.
Yes I am aware similar to the folder option you can specify a query but need help on writing a query and what parameters need to be mentioned in the query.
One more doumb question about where content presenter taskflow is present in the jdev so that I can drag and drop on my portal page. -
How to create a text file or XML file and add content through code into it...
Hi Everyone,
How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
Else say how to create a new XML file through the code and how some content like Example "Hello World".You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
You can then export the file with the doc.exportDataObject method:
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions. -
How do you enable 'Create Content' button on 'Add Content' page?
How do you enable ‘Create Content’ button on ‘Add Content’ page?
There is new functionality to a ‘Layout’ type personalization page like ‘Sales Dashboard’.
Bug 4503123 INCONSISTENT WAY OF ADDING USER-DEFINED REGIONS ON WYSIWYG PAGE:
There’s no way to add custom content to a configurable page.
Add a “Create Content” button and let the user create a piece of content that extends to a region he creates.
It says: Fixed->11.5.10.3CU
In Oracle® Application Framework Personalization Guide Release 11i Part No. B25439-02 it says:
p 4-5
If you personalize a non-configurable page (a page that does not have the necessary metadata to personalize its layout) or when you run your application in Accessibility mode (profile option Self Service Accessibility Features (ICX_ACCESSIBILITY_FEATURES) is set to Standard Accessibility), you will not see the Page Layout Personalization page, as shown below. Instead, you will see the Page Hierarchy Personalization page, page 4-12, where you can perform the same personalization functions, using a descriptive tabular user interface.
It tried this and can’t get it to display.
Has anyone run accross this before?user587952,
Can you describe your issue in detail forgetting those references for the time being. What exactly are you trying to do?
Check this from the dev guide:
In order to be able to take full advantage of page layout personalization capabilities, it is important when you create your configurable page, to use flexibleLayout and flexibleContent regions at all levels when you create the page hierarchy structure under your page layout region. In Oracle Applications, this is required, as it is the coding standard.
--Shiv
Maybe you are looking for
-
How to convert MS SQL Server data to XML data using Java
Hi all! How do I generate XML document for SQL Server data using java / jsp. Thanks in advance
-
[Call for Speakers & Sponsors] March 4th, 2015 - ASUG Ontario
[Call for Speakers & Sponsors] March 4th, 2015 - ASUG Ontario Chapter Meeting Follow our Events on Twitter - @ASUG_Ontario SAP Customer Keynotes by Canada Post and Cirque Du Soliel. Over 150 Attendees from the SAP Ecosystem. SAP Mobility
-
Import pictures, movies/videos, and lyrics?
how can I do all these??? any other software I have to download? or.. just use itunes? @@, thanks~
-
How do I migrate my Windows Photoshop Elements 12 to iPhoto?
I am switching to a Macbook Pro and want to move my photos that are stored with Photoshop Elements 12 on a Windows Laptop. I want to use iPhoto rather than Photoshop Elements for Mac. How do you do this and preserve all the tag information?
-
HTML link to start iChat AV session
Hi: Doesn anyone know of a way to create a link in a web page that will start up iChat (ideally also calling a specific other user).