Proper procedure listen mouse JList in JScrollPane
I have a public class that extends JDialog. On a panel in that frame, I have a Jlist embedded in a JScrollPane. I do have a List Model defined as
private DefaultListModel listModel;I just cant seem to find the right "trick" to grab an entry in the list when I 'click' the mouse on an item in the list.
Any pointers ??
The answer was not easy, so I'll display it for anyone else that runs into the same problem.
private DefaultListModel listModel = new DefaultListModel();
final JList jList1 = new JList(listModel);
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = jList1.locationToIndex(e.getPoint());
System.out.println("Double clicked on Item " + index);
};in jbInit()
jList1.addMouseListener (mouseListener);The trickiest part of this was that the event creator in JBuilder, did NOT use the above procedure to listen to the mouse event and the procedure used by JBuilder would only see mouse events when the JList was empty. Once data was placed in the table, the mouse events were blocked. I'm not sure why, but that was the problem I was having. ALL FIXED with the above code.
Similar Messages
-
Description: If I want to back up to two external hard drives using Time Machine, what is the proper procedure to follow such that I could keep one attached to Time Machine for daily backups, and one that I attach monthly such that I can back it up monthly, and then store it in a fire safe. To do this, what are the exact steps to follow?
Research in Progress:
I selected the "?" icon in Time Machine which took me to "Mac Help - Time Machine Preferences" section. I reviewed this section, including the "Select Backup Disk, Select Disk, Add or Remove Backup Disk." It says, "If you haven’t set up Time Machine, click Select Backup Disk to set up a backup disk. Repeat the steps for each backup disk you want to set up." I did add two backup disks. It goes on to say "If you already set up Time Machine, your backup disks are listed, and information about each backup disk is shown. To select, add, or remove backup disks, click Select Disk or Add or Remove Backup Disk." Well, what is lacking here is what happens when you "Remove" the backup disk.
As I have read this section, it raises additional questions:
What are some cautionary statements.
What happens after you remove a backup disk? Will Time Machine recognize it later?
What is the proper procedure for removing and ejecting one of your external hard drive when you use it with Time Machine? What happens if you don't "remove" a backup drive and instead just drag it to the "trash can, i.e. eject it" and later reconnect it.?Time Machine supports multiple backup drives including network area storage volumes (NAS) as well as physically-connected external backup drives.
In , System Preferences, Time Machine, add the second drive by clicking Select Disk.
All available connected drives including connected network drives are displayed.
Select the additional drives, one at a time.
Connected Network drives are displayed on the desktop only when actively being used by Time Machine for backup.
When prompted, select 'use both' when adding the second drive.
Then choose Select or Remove at the bottom of the list of available devices and network volumes to add additional drives.
Time Machine then automatically rotates backups among the available designated devices and volumes.
If the drive is physically not present, Time Machine skips to the next available backup drive.
To DISMOUNT a drive to take it off-site, it is NOT necessary to remove it from the Time Machine preferences.
When the drive is NOT in use, dismount it by Command+clicking that Drive icon on your desktop (or in Finder) and then "Eject".
That's it.
After 10 days with no backups to a given device, Time Machine does display a message and (as I recall) asks if you want to remove that drive from the rotation.
You can never be too rich or have too many backups! -
HT4623 Trying to install iOS 6 via itunes. Whats the proper procedure to follow?
Trying to install iOS 6 with iTunes, whats the proper procedure to follow?
Connect device to computer. Open iTunes. Select your iPhone under the Devices heading then click on the Summary tab in iTunes' main window. Click on the Update Software button.
-
JList in JScrollPane never shows horizontal scroll bar
I have a JList inside a JScrollPane. When I add a lot of cells to the list, the vertical scroll bar appears as expected. However, if I add a cell that would require lots of horizontal space in which to render, the horizontal scroll bar never appears.
Is there a way to make the JList take on the width of the widest rendered cell?
JoshHere's some code that will demonstrate the problem. Run the code, then resize the window so that the horizontal scroll bar should appear.
Code for jds.toys.Main:
package jds.toys;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class Main extends JFrame {
protected DefaultListModel model;
public Main()
super("JList in JScrollPane");
model = new DefaultListModel();
model.addElement("A very very very very very very long String");
model.addElement("A very very very very very very very long String");
model.addElement("A very very very very very very very very long String");
model.addElement("A very very very very very very very very very long String");
model.addElement("A very very very very very very very very very very long String");
model.addElement("A very very very very very very very very very very very long String");
JList list = new JList(model);
list.setSize(300,300);
list.setFixedCellHeight(30);
list.setCellRenderer(new MyCellRenderer());
JScrollPane scrollPane = new JScrollPane(list);
add(scrollPane);
setSize(400,400);
public static void main(String[] args) throws InterruptedException {
final Main m = new Main();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
m.setVisible(true);
Code for jds.toys.MyCellRenderer:
package jds.toys;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
public class MyCellRenderer extends JPanel implements ListCellRenderer
private Object currentValue;
private JList currentList;
public MyCellRenderer()
public Component getListCellRendererComponent( JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
currentValue = value;
currentList = list;
return this;
public void paintComponent(Graphics g)
int stringLen = g.getFontMetrics().stringWidth(currentValue.toString());
int ht = currentList.getFixedCellHeight();
g.setColor(getBackground());
g.fillRect(0,0,stringLen,ht);
g.setColor(getForeground());
g.drawString(currentValue.toString(),0,ht/2);
} -
Proper procedure for restoring "Connection/Sync" of Apple TV to iTunes
I had a major issue with my Mac. Disk space was dynamically going missing, so i gave up after not being able to solve and bought a new 1TB disk. Reinstalled OSX, and started fresh.
For iTunes, i have always had luck with this restore procedure for the library, etc:
1) Drag and drop all things under Username/Music from old drive to new location.
2) Copy .plist files for iTunes to new install.
3) Launch iTunes. All is good.
now, for Apple TV.... i've had issues with this before.
I need to reestablish this mac as the "owner" or whatever of the Apple TV. I need to ensure the content on the ATV remains and that if i buy something here, it will sync (if selected, etc) to the ATV.
What is the proper procedure for this?
Only thing i care is that the content on the ATV now is still in tact.
Any help?I'm pretty conscientious about adhering to the terms and conditions laid down by , but I don't believe they would stand in the way of someone recovering irreplaceable photos and home videos for example. I've posted this before and to my knowledge not had it removed, so below I've posted a link to one of the ways of recovering your data from the tv.
http://echoone.com/filejuicer/extract-images-from-apple-tv -
What is proper procedure to download an app on an SD Card - MacBook Pro
What is the proper procedure to download an app to an SD card - MacBrook Pro - please show step by step
I have a downloaded an app but do not know how to transfer to the SD Card - Thank you
I do not know which community will help me?Notebooks = all Apple Portable computer support communities
Note: newest 12-inch MacBook is all-new.
If you have an older MacBook (not Pro or Air) there is a separate
section. If you have an vintage G3/G4 Portable iBook/PowerBook
they are also here under Notebooks. Each of the named sections
are generally labeled and accessible from the Welcome to ASC
discussions home page https://discussions.apple.com/welcome .
The MacBook Pro ASC area would befit the computer you're using.
MacBook Pro - Apple Support Community for MacBook Pro users.
Did the article linked in earlier reply help you with the memory card use?
A memory card would appear on the desktop similar to an external hard
disk drive, so items could be 'saved to' it in one of several ways. Or you
can drag & drop items on the icon of the memory card used thus.
The format may make a difference, in some cases, if the
cards are to be used for more than file transfer or storage.
This thread could be moved by a Host to another section, on request.
In any event...
Good luck & happy computing! -
Mouse motion listener for JTable with JScrollpane
Hi All,
I have added mouse motion listener for JTable which is added in JScrollPane. But if i move the mouse, over the vertical/horizontal scroll bars, mouse motion listener doesn't works.
So it it required to add mousemotionlistener for JTable, JScrollPane, JScrollBar and etc.
Thanks in advance.
Regards,
TamizhanI am having one popup window which shows address information. This window contains JTable with JScrollPane and JButton components to show the details. While showing this information window, if the mouse cursor is over popupwindow, it should show the window otherwise it should hide the window after 30 seconds.
To achieve this, i have added mouse listener to JPanel, JTable, JButton and JScrollPane. so if the cursor is in any one of the component, it will not hide the window.
but for this i need to add listener to all the components in the JPanel. For JScrollPane i have to add horizontal, vertical and all the top corner buttons of Scroll bar.
Is this the only way to do this? -
JList/ListCellRenderer/JScrollPane
Hi Listeners!
I'm using a JList using an own renderer for displaying the data.
Every cell contains among other components a text field embedded in a scroll pane. The text field may contain text or images (animated ones).
Both components have information about the available sizes.
The problem comes with displaying the cells because neither the scroll pane nor the animated gif work correctly. Altough the scroll pane is shown I cannot use it and it seems that the scroll pane cannot or does not receive (mouse) events. Finally the animated gif changes to a standard gif without animation. All other things do work.
Has anybody tried to use the JList for presenting scroll pane based content?
ThanX
franzRThanks for the suggestion. With those changes, though, it seems I still have to set the width (setColumns()) inside the renderer in order to get the wrap to occur. getPreferredSize() returns the size of a single line without setting it.
Do you know any way I can access the width of the JList (or the containing JScrollPane), or pass it to the renderer? getPreferredSize() of the JList object yields a StackOverflowError when accessed from within the renderer. -
Proper procedure for patching from Single User mode
Typically when I install a patch cluster from Sun, I do a sanity reboot from the console of the server using:
shutdown -y -g0 -i6
When the system comes back online, I log into the console again and then do:
shutdown -y -g0 -i0 (to go into OBP)
then
boot -s (to go into single user mode)
The procedure above was given to me from a Sun technician.
Then I install the patch cluster and reboot. It has come to my attention that Sun recommends breaking any mirrors between your disks before patching. I wanted to know what is the best way to do this for both Veritas Volume Manager and Solaris Volume Manager. For Veritas Volume Manager, I was thinking of going into the vxdiskadm menu driven utility and choosing the option to "Remove a disk for replacement" for the rootmirror disk and then after a reboot to check that the patches did not cause a problem, go back into vxdiskadm and choose the option "Replace a failed or removed disk" and select the rootmirror which should then begin to automatically resync itself to the primary rootdisk. Any comments on if this is a proper way to do this or if someone has a better method, I would love to hear it. I am assuming a system with just two internal disks: c1t0d0s2 and c1t1d0s2
Also, if anyone can comment on how to do this with Solaris Volume Manager or if it is required would be great also.
Thanks much for any advice.Typically when I install a patch cluster from Sun, I
do a sanity reboot from the console of the server
using:
shutdown -y -g0 -i6
When the system comes back online, I log into the
console again and then do:
shutdown -y -g0 -i0 (to go into OBP)
then
boot -s (to go into single user mode)
The procedure above was given to me from a Sun
technician.Not a bad thing to check reboot before patching, but I don't think it's in any official documentation that I'm aware of.
Then I install the patch cluster and reboot. It has
come to my attention that Sun recommends breaking any
mirrors between your disks before patching.Again, I don't know if it's "official", but if you have a backup copy that you could boot from, it does reduce the possibilities of critical problems from a bad patch.
I wanted
to know what is the best way to do this for both
Veritas Volume Manager and Solaris Volume Manager.
For Veritas Volume Manager, I was thinking of going
into the vxdiskadm menu driven utility and choosing
the option to "Remove a disk for replacement" for the
rootmirror disk and then after a reboot to check that
the patches did not cause a problem, go back into
vxdiskadm and choose the option "Replace a failed or
removed disk" and select the rootmirror which should
then begin to automatically resync itself to the
primary rootdisk. Any comments on if this is a proper
way to do this or if someone has a better method, I
would love to hear it. I am assuming a system with
just two internal disks: c1t0d0s2 and c1t1d0s2
Also, if anyone can comment on how to do this with
Solaris Volume Manager or if it is required would be
great also.Well, it'll work as you've described, but what if the patches fail? The disconnected mirror is not bootable. You'd have to go through an unencapsulation and other things from a CD.
I've often simply pulled one side of the mirror while the machine was shutdown. Since the mirror was valid prior to pulling, it will boot. If there's a problem, I shut down, swap disks, and boot from the untouched mirror. If no problem, I re-insert, reattach the disk to the diskgroup, then recover the volumes.
I don't know of any nice supported method of booting from an offline VxVM mirror that doesn't involve a very long series of steps. My method isn't supported, but it does work. If you have both disks in the machine at the same time though, it'll update the private regions. Don't do that until you're ready to sync up one way or the other. Test before doing it in production.
In any event, you should have a backup ready to go.
Darren -
Problem with a JList and JScrollpane
Hi,
Im having a problem with horizontal scrolling in that I have a simple JList inside a panel and a text box below where the user enters text. Now the text box has a width of 15, but the user can type as many characters as they want..Now the Jlist only displays 15 characters, but the horizontal scroller does not come up, instead just displays for example abcdefghijkl... (the three dots in the end)..
Isnt my scroller supposed to be automatically scrolling when there is more on the line then the screen displays?? I already have this so far..
scroller = new JScrollPane(dataList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);thanks!Try the following code:
package sample;
import java.awt.*;
import javax.swing.*;
public class MyDialog extends JDialog {
public static void main( String[] args) {
new MyDialog().setVisible(true);
JPanel contentPanel = new JPanel();
JScrollPane scrollPane = new JScrollPane();
JList list = new JList( new Object[] {"abcdefghijklmnopqrstuvwxyz", "123456789012345678901234567890"});
public MyDialog() {
contentPanel.setLayout(new BorderLayout());
getContentPane().add(contentPanel);
contentPanel.add(scrollPane, BorderLayout.CENTER);
scrollPane.getViewport().add(list, null);
setSize( 100,100);
setLocation( 100,100);
}Michael -
Synchronize JList with JScrollPane
hi all,
I want to automatically move the scroll in the JScrollPane when I change the selected position in the JList with setSelectedIndex, right now the list is correctly selected, but the scroll remains on the top, how could I move it to position the list to see the selected item?
thanks!
mykroJComponent has a scrollRectToVisible method you could use along with JList's getCellBounds method. Maybe register a ListSelectionListener with the list, then in valueChanged get the newly selected cell's bounds from getCellBounds and call scrollRectToVisible on the JList with the cell bounds.
-
JLists in JScrollPane in JFrame
im writing a form class it extends JFrame has a number of jtextfields and labels
im trying to add a JList in a JScrollPane
the list works alone
everytime i try adding it to a scrollpane it just doesnt show
im not getting any errors either
any ideas
jstfsklh211import java.awt.*;
import java.sql.*;
import java.lang.Object;
import javax.swing.*;
import java.util.*;
public class addevent extends JFrame{
//input fields with options
JComboBox eventType, salesman;
JCheckBox flrplan;
//textfields for input
JTextField date, location, count, ctlstart, cerstart,
dinstart, valnum, valstart, npkn, kipot, textbox,
custinfoID;
JList ctllist,dinlist, buflist;
JButton Add, menu;
//labels for customer info
JLabel custinfof, custinfol, custinfop, custinfoc;
//connection variables
startup bridge = new startup();
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Vector vector1 = null;
private String custID, query;
int j;
public addevent(String title){
this.setTitle(title);
//header
JLabel line = new JLabel();
line.setLocation(0,30);
line.setSize(900,1);
line.setBorder(BorderFactory.createMatteBorder(0,0,1,0,Color.black));
//lists
itemlist("query");
ctllist = new JList(vector1);
ctllist.setSize(200, 250);
ctllist.setLocation(50, 160);
itemlist("query");
dinlist = new JList(vector1);
dinlist.setSize(200, 250);
dinlist.setLocation(350, 160);
itemlist("query");
buflist = new JList(vector1);
buflist.setSize(200, 250);
buflist.setLocation(650, 160);
textbox = new JTextField();
textbox.setVisible(false);
Container contentPane = this.getContentPane();
JScrollPane ctlpane = new JScrollPane(ctllist);
JScrollPane dinpane = new JScrollPane(dinlist);
JScrollPane bufpane = new JScrollPane(buflist);
contentPane.add(ctlpane);
contentPane.add(dinpane);
contentPane.add(bufpane);
contentPane.add(textbox);
this.pack();
this.setSize(900,550);
this.setLocationRelativeTo(null);
this.setVisible(true);
catlist list = new catlist();
public void salesman(){
try {
query = "select * from salesman;";
con = bridge.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery(query);
while(rs.next())
salesman.addItem(rs.getString(1));
catch(Exception ex){ex.printStackTrace();}
finally {
try {
if (rs != null)
rs.close();
catch(Exception ex) {ex.printStackTrace();}
try {
if (stmt != null)
stmt.close();
catch(Exception ex) {ex.printStackTrace();}
public void eventType(){
try {
query = "select * from eventType;";
con = bridge.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery(query);
while(rs.next())
eventType.addItem(rs.getString(1));
catch(Exception ex){ex.printStackTrace();}
finally {
try {
if (rs != null)
rs.close();
catch(Exception ex) {ex.printStackTrace();}
try {
if (stmt != null)
stmt.close();
catch(Exception ex) {ex.printStackTrace();}
public void itemlist(String query){
try {
vector1 = new Vector();
con = bridge.getConnection();
stmt = con.createStatement();
query = "select distinct type from food;";
rs = stmt.executeQuery(query);
while(rs.next()) vector1.add(rs.getObject(1));
catch(Exception ex){ex.printStackTrace();}
finally {
try {
if (rs != null)
rs.close();
catch(Exception ex) {ex.printStackTrace();}
try {
if (stmt != null)
stmt.close();
catch(Exception ex) {ex.printStackTrace();}
}//end classi pulled out about 20 buttons, lables, and textfields
and mutiple get and sets for the text fields
Message was edited by:
jstfsklh211
Message was edited by:
jstfsklh211 -
JLists in JScrollPane with DefaultListModels
Why doesn't this work? When I compile there isn't any scroll pane around the JList. I tried it with an Array of strings instead of a DefautListModel and it worked. I don't know why. If you can't do it with a DefaultListModel, how can I get this 'add(String s)' method without the DefaultListModel?
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.*;
import java.awt.*;
public class MessageHolder extends JFrame
private DefaultListModel messages;
public MessageHolder()
this.setSize(400, 400);
messages = new DefaultListModel();
JList list = new JList(messages);
list.setPreferredSize(new Dimension(250, 100));
JScrollPane pane = new JScrollPane(list);
getContentPane().add(pane, BorderLayout.CENTER);
add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");
add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");
add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");add("HEY");
this.setVisible(true);
public void add(String s)
messages.addElement(s);
}when a component is within a JScrollPane, the scroll bars do not show automatically, only when necessary. You can Manipulate your JScrollPane easily enough through the JScrollPane api...found here http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JScrollPane.html ... the methods you want are the set policy ones, there's one for the vertical and one for the horizontal scroll bar...pass constants from JScrollPane into these methods to force scroll bars to appear as you wish.
-
JTextArea failing proper word wrap within JList
A JTextArea is inserted into a JScrollPane which is being rendered in a JList. Each of these JTextAreas render correctly, except the text within them does not word wrap around the whitespace.
Example, instead of seeing
|Testing 1 2 3 |
|testing. |
------------------we are seeing:
|Testing 1 2 3 tes|
|ting. |
------------------I'm aware the JTextArea component may not have a chance to validate properly, since it isn't visible until it is drawn into the JList. (Note: lineWrap on the JTextArea is set to true).
Is there anything I can do to correct this? Or am I wrong about the cause and there's another solution?I think you're looking for
JTextArea.setWrapStyleWord(true);
Normally I'd yell at you to read the API, but I
remember having a
hard time finding that one myself. :)Looking at the link camickr posted, I saw that in some example code and immediately checked it out. Tried it in my code, and it works.
I'm a big advocate on the API myself, shame on me for missing it! (Glad I'm not the only one tho) -
What is the proper procedure to merge different appln's into a single appln
Hi,
My question is to Frank and Shay.
We are having 2 different applications being developed at 2 different locations.
Now I need to merge them, I have noted the following steps which are to be taken care of, for the procedure to work.
However is there anything else I need to do, or should the steps be done differently.
Please advise.
Considering a basic example we have:
Application1 with 2 projects namely Proj1 and Proj2
Application2 with projects called Proj3 and Proj4
1) Project level: Have all the 4 projects in the same application folder. and set dependencies in the project context so that they can access each other's objects
2) faces-config.xml: Have all the different files in the same /WEB-XML folder, and register them in the web.xml file
Note:
Assuming I have 3 faces-config.xml files
a) faces-config1.xml
b) faces-config2.xml
c) faces-config3.xml
If i have a common Home-page defined in faces-config1.xml; and the same page is referenced in the next file (faces-config2.xml).. so is the application intelligent enough to recognize the redundancy or should something else be done.
3) Application module: Register the different application modules with one-another.
Note: Should all the application modules be present in the same directory folder, cause moving the modules from their initial positions will cause problems, can the modules still be bound together from their original positions
Finally is this all i need to do or are there more steps involved.
Kindly post any and all of your suggestion.
Thanking you,
--ZohebOn your Mac.....
Open Finder > Applications > Utilities > AirPort Utility
Click on the Time Capsule
Click Edit in the smaller window that appears
Click the Disks tab at the top of the next window
Click Erase Disk
Select the Quick Erase option
Click Erase
The operation will only take a minute or two
The disk is now ready for new backups
Maybe you are looking for
-
Can't access any photos, Camera Roll sends me to home screen?
Yesterday I took over 100 photos on my phone for work. After returning to the office and attempting to sync them to the cloud the process froze and never completed. Afterward I am unable to view any of the photos in the Camera Roll. Each time I cli
-
Hey guys, Can anyone please help me find out what is the JDBC url for Yahoo Finance Database that stores the values of the historical stock quotes . I desperately need it for my java application in which I require to access the database in order to g
-
Jsp bean property method dilemma
Hi all, I'm just starting using bean and trying to convert old jsp in MVC model using beans. I expose the problem: a simple internal search engine ask with a form to enter the some parameter. I want to use this parameter to compose my query to the db
-
Overprint Preview is on by default
All of a sudden the Overprint Preview is one when I open a document. How do I turn it off by default> This just started after several years of InDesign work and I can't get it so turn off. Any Ideas? Thanks. AZturtles
-
Is it possible to mix aspect ratios in an iDVD project? I'd like to have a 16x9 menu, a 16x9 movie, and a 4x3 slideshow, since all my pictures are 4x3 and I'd like to avoid windowboxing.