JTree's getRowForLocation, how to get the scroll offset?
I have noticed, that calling getRowForLocation from the mouse event, can give me some unexpected behavior when the scroll bars are visible. What's happening is that when I call getX() and getY() on the mouse handler, it's not offset into the scrollable area. So I end up with row 0, when in fact it's the top row visiable in the scroll pane, but not in the tree.
Any suggestions, pointers?
Use a selectionLister???import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class Test extends JFrame {
JTree jt = new JTree();
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
content.add(new JScrollPane(jt), BorderLayout.CENTER);
jt.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent tse) {
TreePath tp = jt.getSelectionPath();
if (tp!=null) System.out.println(tp.getLastPathComponent());
setSize(100, 100);
setVisible(true);
public static void main(String[] args) { new Test(); }
}
Similar Messages
-
Quick question: How to get the scrolled page number using af:table
Hi,
When using range paging on scrolled table, how to get the current scrolled page number(1,2,3...), for example when moving the table vertical scroll bar forward or backward, is there any method in ViewObjectImpl class that I can use to get such information? I have seen the method scrollToRangePage(int i), but when scrolled ("Fetching data..."), it doesn't not get into this method. So it is wrong usage for this method, right?
ThanksDidn't you just ask that question in this thread?: How to catch the page number when using scroll table in ADF 11g?
A bit of patience might be in order.
CM. -
How to get a scroll bar for nodes?
How to get the scroll bar to work with the javafx.scene.layout.container.
I tried putting in one but the SwingScrollPane requires SwingComponent.
How do I put my fx nodes inside it.
I could not find any way to cast the node objects into SwingComponent.Hi,
Here's a little sample with custom scrollNode
You must modify the code but you can start with it.
* ScrollNode.fx
* Created on 14 mars 2009, 14:53:55
package fxtests;
import fxtests.ScrollNode;
import java.lang.Object;
import javafx.ext.swing.SwingSlider;
import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.text.TextOrigin;
* @author Alex
public class ScrollNode extends CustomNode {
public-init var node: Node;
public-init var nodeWidth: Number;
public-init var nodeHeight: Number;
public var scrollHeight = 20;
public var width = 200;
public var height = 200;
public var posX: Integer = 0 on replace {
node.translateX = -posX
public var posY: Integer =
nodeWidth - width as Integer on replace {
node.translateY = posY-(nodeWidth - width)
public override function create(): Node {
return Group {
content: [
SwingSlider {
value: bind posX with inverse
minimum: 0
maximum: nodeWidth - width as Integer
width: width
height: 20
translateX: 20
vertical: false;
SwingSlider {
value: bind posY with inverse
minimum: 0
maximum: nodeHeight - height as Integer
height: height
width: 20
translateY: 20
vertical: true
Group {
translateX: scrollHeight
translateY: scrollHeight
clip: Rectangle {
width: width
height: height
content: node
Text {
translateX: scrollHeight+10
translateY: scrollHeight+10
textOrigin: TextOrigin.TOP
content: bind "node position: {node.translateX}, {node.translateY}"
function run() {
Stage {
title: "ScrollNode"
scene: Scene {
width: 400
height: 400
content: [
ScrollNode {
width: 200
height: 200
nodeHeight: 500
nodeWidth: 500
node: Rectangle {
width: 500
height: 500
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 1.0
endY: 1.0
stops: [
Stop {
color: Color.WHITE
offset: 0.0
Stop {
color: Color.BLACK
offset: 1.0
} -
How to get the path when i select a directory or a file in a JTree
How to get the path when i select a directory or a file in a JTree
import java.lang.*;
import java.io.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.HeadlessException;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Iterator;
* @author Frederic FOURGEOT
* @version 1.0
public class JTreeFolder extends JPanel {
protected DefaultMutableTreeNode racine;
JTree tree;
protected JScrollPane scrollpane;
final static int MAX_LEVEL = 1; // niveau max de descente "direct" dans l'arborescence
* Sous-classe FSNode
* @author Frederic FOURGEOT
* @version 1.0
private class FSNode extends DefaultMutableTreeNode {
File file; // contient le fichier li� au noeud
* Constructeur non visible
private FSNode() {
super();
* Constructeur par initialisation
* @param userObject Object
FSNode(Object userObject) {
super(userObject);
* Constructeur par initialisation
* @param userObject Object
* @param newFile File
FSNode(Object userObject, File newFile) {
super(userObject);
file = newFile;
* Definit le fichier lie au noeud
* @param newFile File
public void setFile(File newFile) {
file = newFile;
* Renvoi le fichier lie au noeud
* @return File
public File getFile() {
return file;
public JTree getJTree(){
return tree ;
* Constructeur
* @throws HeadlessException
public JTreeFolder() throws HeadlessException {
File[] drive;
tree = new JTree();
// cr�ation du noeud sup�rieur
racine = new DefaultMutableTreeNode("Poste de travail");
// cr�ation d'un noeud pour chaque lecteur
drive = File.listRoots();
for (int i = 0 ; i < drive.length ; i++) {
FSNode node = new FSNode(drive, drive[i]);
addFolder(drive[i], node); // on descend dans l'arborescence du lecteur jusqu'� MAX_LEVEL
racine.add(node);
// Gestion d'evenement sur JTree (on �coute les evenements TreeExpansion)
tree.addTreeExpansionListener(new TreeExpansionListener() {
public void treeExpanded(TreeExpansionEvent e) {
// lorsqu'un noeud est ouvert
// on descend dans l'arborescence du noeud jusqu'� MAX_LEVEL
TreePath path = e.getPath();
FSNode node = (FSNode)path.getLastPathComponent();
addFolder(node);
((DefaultTreeModel)tree.getModel()).reload(node); // on recharche uniquement le noeud
public void treeCollapsed(TreeExpansionEvent e) {
// lorsqu'un noeud est referm�
//RIEN
// alimentation du JTree
DefaultTreeModel model = new DefaultTreeModel(racine);
tree.setModel(model);
setLayout(null);
// ajout du JTree au formulaire
tree.setBounds(0, 0, 240, 290);
scrollpane = new JScrollPane(tree);
add(scrollpane);
scrollpane.setBounds(0, 0, 240, 290);
* Recuperation des sous-elements d'un repertoire
* @param driveOrDir
* @param node
public void addFolder(File driveOrDir, DefaultMutableTreeNode node) {
setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
addFolder(driveOrDir, node, 0);
setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
* Recuperation des sous-elements d'un repertoire
* (avec niveau pour r�cursivit� et arr�t sur MAX_LEVEL)
* @param driveOrDir File
* @param node DefaultMutableTreeNode
* @param level int
private void addFolder(File driveOrDir, DefaultMutableTreeNode node, int level) {
File[] fileList;
fileList = driveOrDir.listFiles();
if (fileList != null) {
sortFiles(fileList); // on tri les elements
// on ne cherche pas plus loin que le niveau maximal d�finit
if (level > MAX_LEVEL - 1) {return;}
// pour chaque �l�ment
try {
for (int i = 0; i < fileList.length; i++) {
// en fonction du type d'�l�ment
if (fileList[i].isDirectory()) {
// si c'est un r�pertoire on cr�� un nouveau noeud
FSNode dir = new FSNode(fileList[i].getName(), fileList[i]);
node.add(dir);
// on recherche les �l�ments (r�cursivit�)
addFolder(fileList[i], dir, ++level);
if (fileList[i].isFile()) {
// si c'est un fichier on ajoute l'�l�ment au noeud
node.add(new FSNode(fileList[i].getName(), fileList[i]));
catch (NullPointerException e) {
// rien
* Recuperation des sous-elements d'un noeud
* @param node
public void addFolder(FSNode node) {
setCursor(new Cursor(3)); // WAIT_CURSOR est DEPRECATED
for (int i = 0 ; i < node.getChildCount() ; i++) {
addFolder(((FSNode)node.getChildAt(i)).getFile(), (FSNode)node.getChildAt(i));
setCursor(new Cursor(0)); // DEFAULT_CURSOR est DEPRECATED
* Tri une liste de fichier
* @param listFile
public void sortFiles(File[] listFile) {
triRapide(listFile, 0, listFile.length - 1);
* QuickSort : Partition
* @param listFile
* @param deb
* @param fin
* @return
private int partition(File[] listFile, int deb, int fin) {
int compt = deb;
File pivot = listFile[deb];
int i = deb - 1;
int j = fin + 1;
while (true) {
do {
j--;
} while (listFile[j].getName().compareToIgnoreCase(pivot.getName()) > 0);
do {
i++;
} while (listFile[i].getName().compareToIgnoreCase(pivot.getName()) < 0);
if (i < j) {
echanger(listFile, i, j);
} else {
return j;
* Tri rapide : quick sort
* @param listFile
* @param deb
* @param fin
private void triRapide(File[] listFile, int deb, int fin) {
if (deb < fin) {
int positionPivot = partition(listFile, deb, fin);
triRapide(listFile, deb, positionPivot);
triRapide(listFile, positionPivot + 1, fin);
* QuickSort : echanger
* @param listFile
* @param posa
* @param posb
private void echanger(File[] listFile, int posa, int posb) {
File tmpFile = listFile[posa];
listFile[posa] = listFile[posb];
listFile[posb] = tmpFile; -
How to get a scroll bar to the applications popup by default?
How to get a scroll bar to the applications popup by default when clicked the applications folder from the dock? If I have so many applications that they do not fit in the default area, I have to find out myselft that I have to scroll the content before the scroll bar appears. This leads to "where is my missing applications questions" by the novice users with Mountain Lion.
System Preferences > General > Show scroll bars.
Click the button by the side of "Always".
Best. -
HT1338 How do you consistently get the scroll bar on the right side of the page
How do you consistently get the scroll bar on the right side of the page.
Go into System Preferences, select General and set "Show scroll bars" to "Always".
-
How to get Auto scroll bar in a JSP?
Hi Gurus,
I have created a custom jsp page in a B2B application. How to get the auto scroll bar when page is exceeded than it can display?
Is there any specific tag or div which is to be included to get this scroll bar?
Thanks a lot in advance!!
Regards,
Lakshman.Hi Lakshman,
You can include it in stylsheet and then use that class in your <body> or "div" tag.
the CSS command is
overflow:auto;
you can use like
<body style="overflow: auto;"> or -- div style="overflow: auto;"
You can declare class in ".css" file
#c1
.c1
<body id="c1>> or <div id="c1">
<body class="c1>> or <div class="c1">
You can use either "class" or "id" by adding it to "CSS" file and the use it to any JSP file or by direct aditing "Style" attirbute in tag.
so when your content is longer then your screen browser will display scroll bar automatically.
I hope this will help you.
Thanks and Regards.
eCommerce Developer
Edited by: Ecommerce Developer on Jul 9, 2009 5:58 PM
Edited by: Ecommerce Developer on Jul 9, 2009 5:59 PM -
How to get motion scroll in adobe muse?
I can't find motion scroll effect in Window Menu and properties bar. So how to get motion scroll in adobe muse. U have any idea?
Hi,
could you please add a screenshot of the windows tab so that we can see what is wrong? -
How could control the scroll events in ALV OO?
Hello experts!
I'm programing a report, inside there is a field that need time of processing. I'm using ALV OO.
I have thought that it could only calculate the field for the lines that visualize.
How could control the scroll events to calculate the field of the visualized lines?
I'm using CL_SALV_TABLE class and cl_salv_events_table to control the events, but there aren't any event to control the scroll.
best regards!Hi Sriram,
I did view the information that you was attaching, but this don't resolve my problem. With methods get_scroll_info_via_id and set_scroll_info_via_id, we can get and put information of selection and view rows in the screen but we don't control when the user click in the scroll for advance or to back down a page.
I would like to refresh the data in ALV when the user view news rows.
I want your genial ideas.
Best regards! -
I or tranfer to my librarypurchased from Itune store a Music app. It is downloaded into intune media/mobile applications. How to get the full album msic/songs into my itunes library or on tomy IPAD? It doesnot open out. Can anybody suggest a way?
If you have a music downloader app (depends on which you have), plug your iDevice into iTunes, go to your device (on itunes), go to your apps, scroll down, and select the app thats holding your music, click on "Save As" (should be located bottom right corner), save the music to your specific folder. Once done, follow through this: Adding music and other content to iTunes and you should have your music on your iDevice music app.
Hope this helps. -
How to get the root node of a tree?
I wanna get all the leaf node of a tree.But JTree have no method about how to get the root TreeNode of a tree.Then how should I do?
try this:
http://javaalmanac.com/egs/javax.swing.tree/GetNodes.html?l=rel -
Does anybody know how to get a scroll bar for a long list of podcasts when selcting some for sync? Thanks
Hi lbadek
I can help with this please send us an email using the contact the mods link in my proifle and we will investigated from there.
Thanks
Stuart
BTCare Community Mod
If we have asked you to email us with your details, please make sure you are logged in to the forum, otherwise you will not be able to see our ‘Contact Us’ link within our profiles.
We are sorry that we are unable to deal with service/account queries via the private message(PM) function so please don't PM your account info, we need to deal with this via our email account :-) -
How to get the tab when is it pressed?
I have the following situation:
I have an array of JTextField inside a scroollpane. The size of my array is nine or ten depends on some rules. But my window show just four JTextField. So I would like to know how to get the event when I press "tab", just to show the others JTextField while I'm pressing "tab". Because I need this event to scrooll down or scrooll up.
I tried the keylistener, but when I press "tab" any method(keypressed, keyreleased, keytyped) is called.
I also tried the focuslistener. If this event I could scrooll down or scrooll up, but I couldn't do both!!
Can somebody help me??
Thanks anyway!!
GinJTextField implements Scrollable interface, which provides information to the enclosing container such as JScrollPane.
Hence when the tab event is fired, you can compute the Rectangle area that should be visible and then call the 'scrollRectToVisible()' method in JTextField. This will inform the JScrollPane to scroll to the rectangle that you mention.
HTH -
Hello as2 image scroll buttons. I can't get the scroll to work
Thank you in advance for your help. I am building an vertical image scroll buttons in AS2. but I cant get the scroll to work. Can you please look at my script and see if I am missing something. Thank you again.
topEdge=mask_mc._y;
maskHeight=mask_mc._height;
sliderHeight=slider_mc._height;
ratio=maskHeight/(sliderHeight-maskHeight)
//trace(ratio)
targY=slider_mc._y;
slider_mc.onEnterFrame=function(){
this._y+=(targY-this._y)/5;
slider_mc.onMouseMove=function(){
if(mask_mc.hitTest(_ymouse,_xmouse,false)){
targY=topEdge-(mask_mc._ymouse/ratio)
updateAfterEvent();Try:
- Reset the iOS device. Nothing will be lost
Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
least ten seconds, until the Apple logo appears.
- Reset all settings
Go to Settings > General > Reset and tap Reset All Settings.
All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
- Restore from backup. See:
iOS: How to back up
- Restore to factory settings/new iOS device.
- Make an appointment at the Genius Bar of an Apple store.
Apple Retail Store - Genius Bar -
Could someone please tell me how to get the voice turned off my iPad and to be able to move freely around on the screen?
A double-tap acts like a single tap and you need to use three fingers to scroll when VoiceOver is on:
Press Home.
Tap Settings. Then double-tap Settings.
Tap General. Then double-tap General.
Use three fingers on the screen to scroll to Accessibility.
Tap Accessibility. Then double-tap Accessibility.
Tap VoiceOver. Then double-tap VoiceOver.
Tap "On" next to VoiceOver. Then double-tap "On" to turn it off.
http://support.apple.com/kb/HT4064
Maybe you are looking for
-
Invoking ORACLE Stored Procedure
Hello guys, I have an ORACLE stored procedure which I need to invoke. I'm currently unable to invoke the stored procedure since I'm always getting the same error: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing
-
How to define parameter variables to be passed by value by default
When defining a new parameter for a sequence, it is set by reference by default. Obviously sometimes when passing a parameter we dont want the sequence receiving those values to be able to modify it by mistake and corrupting the value from the callin
-
updated my i Phone 4 s to os 8 last night now can't get into my apps it requests i sign into iCLOUD HELP PLEASE
-
Have just turned my beloved into a PC by downloading Mavericks. How do I get rid of it?
Have just turned my Apple into a PC by downloading Mavericks. How do I get rid oif it?
-
Setup: Primary database and a physical standby database (READ ONLY). Users need to use the physical standby database for reporting purposes, BUT with very strict password management requirements that their password must be changed every 2 or 3 days.