How can I get current File-Folder location during DnD outside JVM?


Greetings Ranchers,

I want to have a Swing application from which I can drag & drop files between desktop & applications. Dragging and dropping files into JComponents is kind of well documented. But is there way to do the exact opposite copying someting from Swing application to JDesktop

i.e creating a Transferable object using flavor DataFlavor.javaFileListFlavor

If that is not possible is there way to find out what's file loctaion where drop is happening

TIA
Posted On: Tuesday 23rd of October 2012 10:13:51 PM Total Views:  53
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




Why can't i control location of label?

I have background picture and a label that is suppose to go on top of it but i can't seem to control it's location. Setting the location seems to have no effect. I tried increasing the numbers but the textLabel won't budge. It's not exactly at (0,0) of the panel. It is actual 1/4 to the right and less than 1 row down. public BGPanel(ImageIcon background, String msg) { myIcon = background; JLabel textLabel = new JLabel(msg); textLabel.setFont(new Font("sanSerif", Font.BOLD, 12)); textLabel.setForeground(Color.pink); textLabel.setLocation(0,0); //
VIEWS ON THIS POST

41

Posted on:

Monday 22nd October 2012
View Replies!

can't set cursor placement when clicking in a JFormattedTextField...

Ranchers, I have a small but persistent problem. I have a JFormattedTextField created with a MaskFormatter, so that it will only accept eight characters for input. MaskFormatter eightCharMax = null; // limit input size try { eightCharMax = new MaskFormatter("********"); } catch (ParseException e) { // Swallow exception: exception impossible in this scenario } ... customerIDField = new JFormattedTextField(eightCharMax);
VIEWS ON THIS POST

71

Posted on:

Monday 22nd October 2012
View Replies!

ActionListener: Non-static variable 'this' cannot be referenced from a non-static context????

Hi ! I'm not sure why the below code is giving me the error message: 'non-static variable this cannot be referenced from a non-static context', which points to tl, my TimerListener, which implements ActionListener. Is 'this' implied somewhere there that I'm not seeing I'm not sure what 'this' would have to do with my TimerListener\t I've Googled extensively and can't really find any explanation in my text. Does anyone have any ideas or an explanation If need be, I can post my other classes, but I don't think that's the issue here.
VIEWS ON THIS POST

119

Posted on:

Monday 22nd October 2012
View Replies!

how can i drow lines on image with swing

all i have simple Jframe that loads image and display it on Jpanel works great . now i want to draw lines .. simple lines on that image what should i look into , can you please give me link to something that does such thing
VIEWS ON THIS POST

51

Posted on:

Monday 22nd October 2012
View Replies!

Looking for examples of what can be done with Java's GUI tools

all Getting back into the java programming world for the first time in years and am wondering just want are the limits of java's GUI tools I'm hoping that the metal look that greeted me when I last played with Swing is now able to be made at least sort of attractive now. Can someone point me to some examples of Java programs that are pushing the envelope GUI wise in Java Hopefully I explained what I'm after well enough, and
VIEWS ON THIS POST

66

Posted on:

Monday 22nd October 2012
View Replies!

How can I catch the CTRL_C or CTRL_V event

Dear . How can I catch the Ctrl_C or Ctrl_V event in the StyledText widget. Which event listener should I use. KeyListener or anyone else.
VIEWS ON THIS POST

69

Posted on:

Monday 22nd October 2012
View Replies!

can scrollPane be resized automatically?

when we resize a JFrame, is it possible to resize the containing scroll pane with the frame automatically is there any function
VIEWS ON THIS POST

107

Posted on:

Monday 22nd October 2012
View Replies!

can this button be align at the top left coner of a container

import java.awt.event.*; import java.awt.*; import javax.swing.event.*; import javax.swing.*; public class HomePage extends JFrame { JFrame frame; public HomePage() { frame = new JFrame("Home"); frame.setBounds(100, 100,600,500); setGUIPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setGUIPanel() { Container content = frame.getContentPane(); content.setLayout(new BorderLayout(10,10)); //create a Base panel to hold navigation and display panels JPanel basePanel = new JPanel(); basePanel.setLayout(new GridLayout(0,2,5,5)); content.add("Center",basePanel); //create left panel and it's components and //add to the Base panel JPanel navPanel = new JPanel(); //Dimension size = new Dimension(80,20); Box controlBox = Box.createVerticalBox(); JButton main = new JButton("Main"); //main.setPreferredSize(size); JButton employ = new JButton("Employee"); //employ.setPreferredSize(size); JButton admin = new JButton("Admin"); //admin.setPreferredSize(size); //add button to the BoxLayout controlBox.add(main); controlBox.add(employ); controlBox.add(admin); //add controlBox to navPanel navPanel.add(controlBox); //add navPanel to BasePanel basePanel.add(navPanel); frame.setVisible(true); } public static void main(String[] args) { HomePage hp = new HomePage(); } }
VIEWS ON THIS POST

95

Posted on:

Monday 22nd October 2012
View Replies!

How i can get Folder Explorer

hi does java has Folder Explorer like windows one (GUI) what is api name
VIEWS ON THIS POST

50

Posted on:

Monday 22nd October 2012
View Replies!

Why I cannot Move my JLabel after I add SetToolTipText()??

Dear Friends: I met a tough problem that I debugged for few days but cannot solve it. after I add SetToolTipText I cannot Move my JLabel , what is wrong here\t see code below, here label1 cannot move. If somebody can throw some lights, that will be wonderful, so far no progress. import java.awt.*; import java.awt.event.*; import java.util.Vector; import javax.swing.*; import javax.swing.border.LineBorder; import javax.swing.event.*; public class DNDJLabels extends JPanel { protected JLabel label1, label2, label3, label4; protected JLabel[] labels; protected JLabel selectedLabel; LineBorder black = new LineBorder(Color.black, 3, false); int cx, cy; protected Vector order = new Vector(); public static void main(String[] args) { JFrame f = new JFrame("Connecting Lines"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new DNDJLabels()); f.setSize(600,700); f.setLocation(200,200); f.setVisible(true); } public DNDJLabels () { setLayout(null); addLabels(); label1.setBounds( 125, 150, 150, 60); label2.setBounds(425, 150, 150, 60); label3.setBounds( 125, 575, 150, 60); label4.setBounds(425, 575, 150, 60); label1.setBorder(black); label2.setBorder(black); label3.setBorder(black); label4.setBorder(black); //add(btn); label1.setToolTipText("AAAAAAAA"); determineCenterOfComponents(); ComponentMover mover = new ComponentMover(); addMouseListener(mover); addMouseMotionListener(mover); } public void paintComponent(final Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); Point[] p; g2.setStroke(new BasicStroke(4f)); for(int i = 0 ; i < order.size()-1; i++) { JLabel l1 = (JLabel)order.elementAt(i); JLabel l2 = (JLabel)order.elementAt(i+1); p = getCenterPoints(l1, l2); g2.setColor(Color.black); //g2.draw(new Line2D.Double(p[0], p[1])); } } private Point[] getCenterPoints(Component c1, Component c2) { Point p1 = new Point(), p2 = new Point(); Rectangle r1 = c1.getBounds(), r2 = c2.getBounds(); p1.x = r1.x + r1.width/2; p1.y = r1.y + r1.height/2; p2.x = r2.x + r2.width/2; p2.y = r2.y + r2.height/2; return new Point[] {p1, p2}; } private void determineCenterOfComponents() { int xMin = Integer.MAX_VALUE, yMin = Integer.MAX_VALUE, xMax = 0, yMax = 0; for(int i = 0; i < labels.length; i++) { Rectangle r = labels[i].getBounds(); if(r.x < xMin) xMin = r.x; if(r.y < yMin) yMin = r.y; if(r.x + r.width > xMax) xMax = r.x + r.width; if(r.y + r.height > yMax) yMax = r.y + r.height; } cx = xMin + (xMax - xMin)/2; cy = yMin + (yMax - yMin)/2; } private class ComponentMover extends MouseInputAdapter { Point offsetP = new Point(); boolean dragging; public void mousePressed(MouseEvent e) { Point p = e.getPoint(); for(int i = 0; i < labels.length; i++) { Rectangle r = labels[i].getBounds(); if(r.contains(p)) { selectedLabel = labels[i]; order.addElement(labels[i]); offsetP.x = p.x - r.x; offsetP.y = p.y - r.y; dragging = true; repaint(); //added break; } } } public void mouseReleased(MouseEvent e) { } public void mouseDragged(MouseEvent e) { Rectangle r = selectedLabel.getBounds(); r.x = e.getX() - offsetP.x; r.y = e.getY() - offsetP.y; selectedLabel.setBounds(r.x, r.y, r.width, r.height); //determineCenterOfComponents(); repaint(); } } private void addLabels() { label1 = new JLabel("Label 1"); label2 = new JLabel("Label 2"); label3 = new JLabel("Label 3"); label4 = new JLabel("Label 4"); labels = new JLabel[] { label1, label2, label3, label4 }; //add(btn); for(int i = 0; i < labels.length; i++) { labels[i].setHorizontalAlignment(SwingConstants.CENTER); labels[i].setBorder(BorderFactory.createEtchedBorder()); add(labels[i]); } } }
VIEWS ON THIS POST

76

Posted on:

Monday 22nd October 2012
View Replies!

Why can't I adjust my buttons location in the frame?

Hi . I can't seem to reallocate my buttons location with the current program format. I do not wish to use grid bag layout as I would attach some images and will be changing their location at some point of time. I'm using setBounds. Can someone help me understand why is that so The program I've attached is a small portion of it. import java.awt.*; import java.awt.event.*; import javax.swing.*; //Singapore news class UI2_SGNewsMenu extends JFrame { Color blue = new Color (0,0,255); Color violet = new Color (162,142,222); public Font originalfont = new Font("serif", Font.BOLD, 20); private static UI2_SGNewsMenu ui2_sgnewsmenu = new UI2_SGNewsMenu(); int clear,set; public JButton TvSeriesButton[] = new JButton[3]; int current2 = 0; public void checkclear() { TvSeriesButton[clear].setBackground(violet); } private void checkset() { TvSeriesButton[set].setBackground(blue); } private UI2_SGNewsMenu() { for(int i=0;i < TvSeriesButton.length;i++) { TvSeriesButton[i] = new JButton(); TvSeriesButton[i].setFont(originalfont); if(i>=1) { TvSeriesButton[i].setBackground(violet); } } TvSeriesButton[0].setBackground(blue); TvSeriesButton[0].setText("Prison Break"); TvSeriesButton[1].setText("Heroes"); TvSeriesButton[2].setText("SmallVille"); TvSeriesButton[0].setBounds(new Rectangle(256, 190, 180, 40)); TvSeriesButton[1].setBounds(new Rectangle(280, 250, 135, 31)); TvSeriesButton[2].setBounds(new Rectangle(280, 310, 135, 31)); JPanel sub2 = new JPanel(); sub2.add(TvSeriesButton[0]); sub2.add(TvSeriesButton[1]); sub2.add(TvSeriesButton[2]); setContentPane(sub2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(1024,768); setFocusable(true); addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_ESCAPE) { System.exit(0); } if(e.getKeyCode() == KeyEvent.VK_UP) { current2--; for (int x=0;x
VIEWS ON THIS POST

52

Posted on:

Monday 22nd October 2012
View Replies!

Is Swt how can i calculate the drop in DND action

im trying to make simple DND operation , dragging button from one side to composite now the DND is working great , but when i drop the button its always to fixed location in the composite control , i want to be able to drop it depending on where i drop the button that is any where in the composite area . how can i do that
VIEWS ON THIS POST

57

Posted on:

Monday 22nd October 2012
View Replies!

How can I split JButton? Any idea?

I just need a regular JButton that will differently respond if a user click at left or right half of the JButton. It will serve as "Back/Forward" buttons, but mixed into single JButton. Any idea on how to implement such functionality
VIEWS ON THIS POST

66

Posted on:

Monday 22nd October 2012
View Replies!

can anyone tell me books to refer for Swings

Need some input regarding the names of the books specifially for Swings. I am working with it, so I know the basics.But kindly suggest some book names which are not very huge .
VIEWS ON THIS POST

63

Posted on:

Monday 22nd October 2012
View Replies!

How i can make a JInternal frame to Doc in right side of my Jdesktop ?

Hi Thank you for reading my post is there any way to dock a JinternalFrame in a side of JDesktop component
VIEWS ON THIS POST

50

Posted on:

Monday 22nd October 2012
View Replies!

Which design pattern can be appied here?

Somthing like this TableModel --> dataFilter --> table1 table2 table 3 In a word, when set different condition in the dataFilter, it will have differnet tables. I think there is some design pattern can be appied here to make the design easily.
VIEWS ON THIS POST

41

Posted on:

Tuesday 23rd October 2012
View Replies!

how i can make a JinternalFrame un-moveable

Hi Thank you for reading my post How i can prevent users from moving a JInternalFrame in an JDesktop component I have several Internal frame inside a Jdesktop and i want some of them to be fixed in regard to their location.
VIEWS ON THIS POST

73

Posted on:

Tuesday 23rd October 2012
View Replies!

How can I send text characters to a printer device ?

If I want to write text characters to a file, I can try the following: BufferedWriter out = new BufferedWriter(new FileWriter("myFile.txt")); out.write(line1); out.write(line2); out.write(line3); (...) out.write(line999); out.flush(); out.close(); What should I change in the above lines in order to write streams of characters to a printer device instead of a file Please, keep in mind that I could need to print more than one page of text characters.
VIEWS ON THIS POST

60

Posted on:

Tuesday 23rd October 2012
View Replies!

Why my JSplitPane can't hide or show as I want?

import javax.swing.*; import java.awt.event.*; import java.awt.event.ActionEvent; import java.awt.BorderLayout; import java.awt.Dimension; public class SplitPaneTest implements ActionListener{ boolean show = false; JButton buttonB = new JButton("Show or Hide"); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); public SplitPaneTest() { JFrame frame = new JFrame("SplitPane show and hide test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultLookAndFeelDecorated(true); frame.setSize(500, 400); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); JButton button = new JButton("OK"); button.addActionListener(this); splitPane.add(button, JSplitPane.TOP); splitPane.add(buttonB, JSplitPane.BOTTOM); // splitPane.setResizeWeight(0.3); hide(); frame.getContentPane().add(splitPane, BorderLayout.CENTER); frame.setVisible(true); } public void actionPerformed(ActionEvent actionEvent) { if(show) { hide(); show = false; } else { show(); show = true; } } public void hide() { splitPane.setDividerLocation(1000); buttonB.setVisible(false); } public void show() { splitPane.setDividerLocation(20); buttonB.setVisible(true); } public static void main(String[] args) { new SplitPaneTest(); } }
VIEWS ON THIS POST

51

Posted on:

Tuesday 23rd October 2012
View Replies!

How to add a JButton to SplitPaneDivider? (why it can't work?)

Hi friends: In a JApplet, I want to add a JButton to SplitPaneDivider.But the code seem's don't work property. My code is: ////////////// TestApplet extends JApplet //////////////// public class TestApplet extends JApplet { public void paint(Graphics g) { JPanel f=new JPanel(); f.setPreferredSize(new Dimension(300,200)); f.setBackground(Color.green); f.setVisible(true); f.setLayout(new BorderLayout()); JButton jep=new JButton("b"); JSplitPane jspcontent=new JSplitPane(JSplitPane.VERTICAL_SPLIT,f,jep); jspcontent.setOneTouchExpandable(true); jspcontent.setDividerSize(50); BasicSplitPaneUI bspUI=(BasicSplitPaneUI)jspcontent.getUI(); JButton b=new JButton("test"); b.setVisible(true); BasicSplitPaneDivider divi=bspUI.getDivider(); divi.add(b); divi.setVisible(true); divi.validate(); this.setContentPane(jspcontent); this.setVisible(true); this.validate(); } } ///////////// end ////////////////// The divider can't display the JButton, why But in a frame (None JApplet ) application, it can work property. Does the JApplet can't use BasicSplitPaneDivider :roll: Thks!
VIEWS ON THIS POST

57

Posted on:

Tuesday 23rd October 2012
View Replies!