JList item selected displayed Twice...Please suggest
Folks,
The selected value from the JList is being displayed twice.
I am unable to figure out why this is being displayed twice.
Can anyone suggest??
If you click Black..it will de displayed twice!!!!
public class JListDemo extends JFrame{
private JList colorList;
private Hashtable ht;
private Container c;
private String colorNames[] = {"Black", "Blue","Red","Green","Yellow"};
public JListDemo() {
super("JList Demo");
c = getContentPane();
c.setLayout(new FlowLayout());
//** Create a List
colorList = new JList(colorNames);
colorList.setVisibleRowCount(3);
colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
c.add(new JScrollPane(colorList));
//** Set up Event Handler.
colorList.addListSelectionListener(
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e)
System.out.println(colorList.getSelectedValue());
setSize(1000,550);
show();
public static void main(String[] args) {
JListDemo JListDemo1 = new JListDemo();
So if you click
Sure, the Swing tutorial on "Using Lists" will explain whats happening and give you a solution:
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html#selection
Similar Messages
-
JList item selected is displayed twice. Please Assist
Folks,
I have this strange behaviour when I select an item from the JList.
When I select the an item, it gets displayed twice.
Can anyone tell me why this is being displayed twice?
I am also checking the Java Sun Swing tutorials site..but no luck as yet.
Attached is a short class.
If you click on Black or Blue etc ,it gets displayed twice...
public class JListDemo extends JFrame{
private JList colorList;
private Container c;
private String colorNames[] = {"Black", "Blue","Red","Green","Yellow"};
public JListDemo() {
super("JList Demo");
c = getContentPane();
c.setLayout(new FlowLayout());
/** Create a List */
colorList = new JList(colorNames);
colorList.setVisibleRowCount(3);
colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
c.add(new JScrollPane(colorList));
//** Set up Event Handler.
colorList.addListSelectionListener(
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e)
System.out.println(colorList.getSelectedValue());
setSize(1000,550);
show();
public static void main(String[] args) {
JListDemo JListDemo1 = new JListDemo();
}in your ListSelectionListener you must check if the event is one of multiple change events. In your case you get one event when the mouse first selects an item and possible more when you move the cursor over the other entries. If you are only interested in the final selection check if e.getValueIsAdjusting() is false.
// not interested in events if they are not final
if (e.getValueIsAdjusting())
return;
// do what ever you want
System.out.println(colorList.getSelectedValue());
...Hope this helps! -
Double click for JList items selection
I would like to select JList items only by double clicking on them. I can write a mouse listener for detecting double clicks by my own (and handle it afterwards), by please tell me how to turn the default behavior off (selecting items by clicking one time).
Thanks in advance
MarekI would like to select JList items only by double clicking on them. Well the standard is to select or highlight on a mouseClick or by using the arrow keys on the keyboard.
Then once you have a selected item you can perform and Action on the item by double clicking or by using the enter key. Remember you should always be able to use either the keyboard or the mouse to perform any given function.
This posting shows my solution for the above scenario:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=626866 -
I am using a JList, and I would like to select certain items in the list. Right now I am doing it by passing the constructor an array of int indecies that correspond to the items I want selected.
What I would really like to do, is have one item selected in red and the others selected the way they are. Or the other way around. I just want different color selections. I'm pretty sure I can not do this, but I just wanted to see if you guys (and gals) had any ideas.
The other idea I had was to use a JPanel, and then use drawString to list the items, then capture the mouse click, find what item was selected, and then paint that rectangle the color I want.Hi
You need to write a custom ListCellRenderer and set that for the list using: list.setCellRenderer(someCellRenderer); Once you have done that, populate the list with items (i.e. instances of a class which you created) that define whether the list item being drawn should be drawn using a red foreground. The renderer will need to check and see if the list item boolean value for painting in red is true, and if so set the foreground to red, otherwise use the default foreground color.
Sorry if this sounds cryptic but I can't devote any more time to helping you out. Best of luck.
cheers,
Greg -
SAP Script Check printing Layout, Line Items to display twice in First Page
Hi All,
This requirement is for US check printing Layout.
My Requirement is to display Items twice on the first page.
Eg : Main Window has 10 Items, I need to display all the Items at the bottom in another window at the bottom.
I can't create 2 Main windows in the first page, as the data from the Main window 1 overflows to Main window 2 in the first page.
I copied print program RFFOUS_C into a Z-version and try to implement the logic, however unable to print the line items in the bottom window.
Kindly give your valuable Inputs.
Thanks
VinayakHi
I had the same request for a check form in Canada. I solved it by writing the line item output into variables and print these variables in a second window. It was ~10 hours of effort, not a real nice technical solution but it worked.
If you require I can send you a PDF of the sap script form definition. You can contact me at [email protected] Answers can take 1 week or more.
Best regards
JD -
Hi ALL ,
Iam a business object XI Developer ,Now i have an option to go SAP BW or to continue working in Businessobjects and SAP acquired BO .Its confusion for me which one to select
can anyone please suggest which way is best .
Thanks & Regards
Sameer Khanhi,
if you know BO, and have he option to work with BI its good hope u could proceed with BI.
Business one
http://www.ciol.com/content/news/2006/106012308.asp
http://contextlabs.in/pdfs/SAP_Business_One-Brochure.pdf
Ramesh -
Clicking (and selecting) the same JList item twice
I have a JList with items (Strings) which should be added to another String when selected (clicked on). My problem is that when a user clicks twice on the same item it should be added to the result String twice. But a ListSelectionListener acts only when the value has changed, so when an other item is selected.
Does anyone know a neat (as high level as possible) solution for this?
P.S.: How do you assign duke dollars to a topic? And how do you give someone who replies those?Thanks. I also already thought of adding a MouseListener, but I kind of wanted to avoid it. But it seems that it is necessary if I want to keep the selection.
The solution I have now, by the way, is that I set the selectedIndex back to -1 in valueChanged, so there is never any item selected. -
Attempting to Get Specific Items Selected from a JList
Hello all, back again...
I'm working on a simple interface that can run an SQL query with specific settings, and these settings can be altered by choosing one or multiple options from a JList to the side of the table that displays the results. My problem is, currently, not being able to figure out how to get the accursed thing to tell me what items in the JList are selected!
I've tried using:
int multiselect[] = cmbSystems.getSelectedIndices();...but it inevitably returns an array with a size of 1. Frustrating. I know I'm missing something, but I have no idea what. What am I doing wrong? Thanks!
~ MattMystrunner wrote:
Hmm, okay... give me a bit to figure that out, and I will. :)Sure. Your SSCCE should probably only consist of a JList that prints out the selected items when the selection changes, or something like that. I would bet that you figure out what's going wrong in the process of boiling your code down to the SSCCE. -
Delete Selected JList Item on Pressing Delete Key
Hi,
I have to delete selected JList item ((in JFrame using java Swing) after pressing Delete key. Please provide me code for this.
Thanks
NitinAgain read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/list.html]How to Use Lists and [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings.
Are you sensing a common theme here? Do some reading on your own. The tutorial has most of the information you need. -
My thuderbolt display is 3 weeks old which I'm using as display for my mac mini. I no longer get the display on but can hear the sound. Please suggest.
Make sure the mini-displayport/TB plug is fully seated. It may look fully plugged in but isn't.
Make sure the Displays system preferences has an Arrangement tab. No Arrangement means the monitor is not being detected.
Do a smc reset.
If none of this works I suggest you take it back to apple (along with your mini). -
Please suggest a select query / sub query with out using any subprograms or
source table: Three columns ORIGIN, DESTINATION,MILES
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Melbourne Sydney 1000
Brisbane Sydney 1000
Perth Darwin 4000
Sydney Brisbane 1000
out put :Three columns ORIGIN, DESTINATION,MILES
Duplicate routes are to be ignored so the output is
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Brisbane Sydney 1000
Perth Darwin 4000
Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Hi,
user9368047 wrote:
... Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Why? If the most efficient way to get the results you want involves using a function, why wouldn't you use it?
Here's one way, without any functions:
SELECT a.*
FROM source_table a
LEFT OUTER JOIN source_table b ON a.origin = b.destination
AND a.destination = b.origin
AND a.miles = b.miles
WHERE b.origin > a.origin -- Not b.origin > b.origin
OR b.origin IS NULL
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
Edited by: Frank Kulash on Nov 6, 2012 7:39 PM
Corrected WHERE clause after MLVrown (below) -
Need guidance in where caluse of a select query.Please suggest.
Hi All,
I have a internal table IT_INPUT which includes multiple cost centers . Now for all entries in IT_INPUT-COst center i want to selct the records from COP table. The issue i am fasing is - Cost center is concatenated with some other values and stored in OBJNR field of COSP table like ex KSSPS1SF518 (SF518 is a cost center here, thease fields are of variable lenth)
ex :
SELECT objnr gjahr wrttp versn kstar wkf001 wkf002 wkf003 wkf004
wkf005 wkf006 wkf007 wkf008 wkf009 wkf010 wkf011 wkf012
FROM cosp INTO TABLE it_cosp
FOR ALL ENTRIES IN it_input
where objnr?
what should we give in where claue. please suggest
Thanks,
RaviYou can use the code a little modification of a above code...
we will concatenate 2 * before and after the cost center. this will allow us to get the right result
check it and let me know
data:lr_objnr type range of cosp-objnr.
data:wa like line of lr_objnr.
wa-option = 'CP'.
wa-sign = 'I'.
Concatenate '*'
'SFS18' <cost center>
INTO wa-low.
append wa to lr_objnr.
SELECT objnr gjahr wrttp versn kstar wkf001 wkf002 wkf003 wkf004
wkf005 wkf006 wkf007 wkf008 wkf009 wkf010 wkf011 wkf012
FROM cosp INTO TABLE it_cosp
FOR ALL ENTRIES IN it_input
where objnr in lr_objnr. -
Please suggest the URL to display JSP report
Hi Experts,
Last week, we tried to change the memory of Response Cache and buffer Cache to increase the speed of the Excel report. But it didn’t work out.
And from the below link, I understood we can convert the oracle 9i report to excel by converting the Oracle 9i report to JSP report.
http://www.oracle.com/technology/products/reports/htdocs/getstart/demonstrations/index.html
I’ve converted the Oracle 9i report to JSP report and finding the way to display the JSP report using Application Server. I am trying to find out the REPORT URL of simple JSP report and using Reports Servlet . Right now I am trying the below steps to display the JSP report in Application Server.
Please suggest the URL for displaying the JSP report
Thanks & RegardsPlease explain how any of this relates to the topic of this forum: "Database Upgrade."
If you repost your question in the correct forum, or perhaps with the correct company, will be more likely to find the help you need. For example ... what App Server (make and model).
Thank you? -
How to delete items selected in a JList?
Ahoy,
I hava made a Multiple selection list (two list: one for
the items that might be selected and another one
for the selected items). How can I delete the (faultly) selected items in the second list?
Thanx,
// create function button
copy = new JButton( ">>" );
delete = new JButton ( "<<");
copy.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
// place selected values in functionList
copyList.setListData(
functionList.getSelectedValues() );
delete.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent e )
// delete selected items from copyList
);You must get the selected item and remove from the model...
delete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int si = list.getSelectedIndex(); //get the index of the item selected
if (si > -1) { //to validate that be selected
listModel.removeElementAt(si); //remove from the listmodel
modifyTextField.setText("");
});in this url you can see a complete sample..
http://www.esus.com/javaindex/j2se/jdk1.2/javaxswing/atomiccontrols/jlist/addtojlist.html -
Key pressed in Jlist and selecting the item of key list accordingly
Hi,
I have a JList with the items in sorted order.Now I want that if a person presses any key (say K) then the first item starting with K should be selected.Hmmm I can do it by addding a key listener to the list and cheking all the items in the list ,by traversing through the whole lenght of JList and selecting the item if it starts with the character of the key pressed.
But i was thinking if there is any better way to do that?
Regards Aminsee bugid: 4654916 - it does say that the the
scrolling for the JList should now work with keyboard
selection.I have the same problem. Thanx for the hint with the bugid. Saw a good workaround there with a simple subclass of JList. Works for me although it is annoying to subclass JList all the time. The bug seems not to be fixed in the 1.4.1 JDK.
Andreas
Maybe you are looking for
-
How can I determine how many pages my Laserjet 1020 printer has printed in its lifetime?
I am trying to be proactive in determining whether I need to plan to replace my Laserjet 1020 printer. I know that I have seen printouts from resellers/refurbishers which show the number of pages that a printer has printed in its lifetime. I am jus
-
Search for a file name by time stamp
Powershell allows us to append the date faily easily to a file name (eg. "test.txt $(get-date -f dd-MM-yyyy).txt"). I'm looking for a simple script to search for a powershell script by a static name with todays date appended. I then want to move th
-
Missing download not showing in my library or files
yes i did go to store thats where i found that i had no pending downloads its not in my library or my music files i cant find it .as i read i see that i,m not the only one thats had this problem !
-
[SOLVED] Reinstallation: Blank config files?
OK, so I managed to hose my first Arch install (forgot to rehash the passwords after switching to sha512. D'oh!) so I decided to reinstall - probably not the easiest way to do it, I know, but I'm trying to learn Arch, so I thought I'd give it a try.
-
Dear Experts, we have configured the LWF (T7INU1, T7INU3 AND V_7IN0P_ALL) for Gujarat employees with Universal type 04, Region 06 and slab code LWGJ03. When I run simulation for these employees,it is displaying the error message "No entries in table