hi all, I am copying some cells from excell... JPopupMenu popup; JTable table; public BasicAction cut, copy, paste, selectAll...); copy = new CopyAction("Copy", null); paste = new PasteAction("Paste",null)
April 15, 2008 at 8:02 PM
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.table.*;
public class TCPopupEventQueue extends EventQueue {
public JPopupMenu popup;
JTable table;
public BasicAction cut, copy, paste, selectAll;
public TCPopupEventQueue() {
//createPopupMenu();
}
public void createPopupMenu(JTextComponent text){
cut = new CutAction("Cut",null);
copy = new CopyAction("Copy", null);
paste = new PasteAction("Paste",null);
selectAll = new SelectAllAction("Select All",null);
cut.setTextComponent(text);
copy.setTextComponent(text);
paste.setTextComponent(text);
selectAll.setTextComponent(text);
popup = new JPopupMenu();
popup.add( cut );
popup.add( copy );
popup.add( paste );
popup.addSeparator();
popup.add( selectAll );
}
public void showPopup(Component parent, MouseEvent me){
popup.validate();
popup.show(parent, me.getX(), me.getY());
}
protected void dispatchEvent(AWTEvent event){
super.dispatchEvent(event);
if(!(event instanceof MouseEvent)){
return;
}
MouseEvent me = (MouseEvent)event;
if(!me.isPopupTrigger()) {
return;
}
if( !(me.getSource() instanceof Component) ) {
return;
}
Component comp = SwingUtilities.getDeepestComponentAt((Component)me.getSource(),me.getX(), me.getY());
if( !(comp instanceof JTextComponent)){
return;
}
if(MenuSelectionManager.defaultManager().getSelectedPath().length > 0){
return;
}
createPopupMenu((JTextComponent)comp);
showPopup((Component)me.getSource(), me);
}
public abstract class BasicAction extends AbstractAction{
JTextComponent comp;
public BasicAction(String text, Icon icon) {
super(text, icon);
putValue(Action.SHORT_DESCRIPTION, text);
}
public void setTextComponent(JTextComponent comp){
this.comp = comp;
}
public abstract void actionPerformed(ActionEvent e);
}
public class CutAction extends BasicAction {
public CutAction(String text, Icon icon) {
super(text, icon);
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl X"));
}
public void actionPerformed(ActionEvent e){
comp.cut();
}
public boolean isEnabled(){
return comp != null && comp.isEditable() && comp.getSelectedText() != null;
}
}
public class CopyAction extends BasicAction{
public CopyAction(String text, Icon icon){
super(text,icon);
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl C"));
}
public void actionPerformed(ActionEvent e) {
comp.copy();
}
public boolean isEnabled() {
return comp != null && comp.getSelectedText() != null;
}
}
public class PasteAction extends BasicAction{
public PasteAction(String text, Icon icon){
super(text,icon);
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl V"));
}
public void actionPerformed(ActionEvent e) {
comp.paste();
}
public boolean isEnabled() {
Transferable content = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
return comp != null && comp.isEnabled() && comp.isEditable()
&& content.isDataFlavorSupported(DataFlavor.stringFlavor);
}
}
public class SelectAllAction extends BasicAction{
public SelectAllAction(String text, Icon icon){
super(text,icon);
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl A"));
}
public void actionPerformed(ActionEvent e){
comp.selectAll();
}
public boolean isEnabled() {
return comp != null && comp.isEnabled() && comp.getText().length() > 0
&& (comp.getSelectedText() == null ||
comp.getSelectedText().length() < comp.getText().length());
}
}
public static void main(String[] args) {
Toolkit.getDefaultToolkit().getSystemEventQueue().push( new TCPopupEventQueue());
JTextField field = new JTextField(20);
JTextField field1 = new JTextField(20);
JPanel center = new JPanel( new FlowLayout(FlowLayout.LEFT) );
center.add(new JLabel("cell1:"));
center.add(field);
center.add(new JLabel("cell2:"));
center.add(field1);
JPanel content = new JPanel( new FlowLayout(FlowLayout.LEFT) );
content.add( center, BorderLayout.SOUTH );
JFrame frame = new JFrame("cell copy past program");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(content);
frame.setSize(550,100);
frame.setVisible(true);
}
}
Related Tutorials/Questions & Answers:
Copy and pasting - Java BeginnersCopy and pasting hi all, I am copying some cells from excell... JPopupMenu popup; JTable table; public BasicAction cut,
copy, paste, selectAll...);
copy = new CopyAction("
Copy", null); paste = new PasteAction("Paste",null)
Array copyArray copy Hello all.
could someone telle me how to
copy an array (holding random numbers)
to a new array...( then make randomnumbers on this new array ) but without changing the excisting array ?
last . possibility
Advertisements
copy() exampleCopying a file in PHP
In this example, you will learn 'how to
copy a file in PHP programming language?'
For copying a file, we use
copy command from source to destination within PHP code tag like ADS_TO_REPLACE_1
copy ($source
cut,copy,pastecut,
copy,paste plz... give me the coding of cut,
copy and paste in Java (Netbeans
Copy .mdb file for backup.Copy .mdb file for backup. hi..
i am new to java...
in my application , at one place for taking back up i have to
copy .mdb file from one place... tell me for multiple files of multiple type...how we can
copy..
thank you
copy file - Java Beginnerscopy file i want to
copy file from one folder to another
Hi Friend,
Try the following code:
import java.io.*;
public class CopyFile{
public void
copy(File src, File dst) throws IOException
data copy - SQLdata copy
how to
copy values of one column from one table into another column of another table? Hi
INSERT INTO table_name (column_name)
AS SELECT DISTINCT VALUES FROM table_name (column_name
Copy Files - Java BeginnersCopy Files I saw the post on copying multiple files (http://www.roseindia.net/java/example/java/io/CopyMultipleFiles.shtml) and I have something... and then
copy it to the folder I need.
Does anyone have a similar program
JavaScript Copy Array
JavaScript
Copy Array
... useful in
complex applications. In this section, you will study how to
copy an array...;
<h2>
Copy Array Example</h2>
<script language="javascript
ModuleNotFoundError: No module named 'copy-pase'ModuleNotFoundError: No module named '
copy-pase' Hi,
My Python... '
copy-pase'
How to remove the ModuleNotFoundError: No module named '
copy... have to install padas library.
You can install
copy-pase python with following
ModuleNotFoundError: No module named 'copy-pase'ModuleNotFoundError: No module named '
copy-pase' Hi,
My Python... '
copy-pase'
How to remove the ModuleNotFoundError: No module named '
copy... have to install padas library.
You can install
copy-pase python with following
ModuleNotFoundError: No module named 'krunk-copy'ModuleNotFoundError: No module named 'krunk-
copy' Hi,
My Python... 'krunk-
copy'
How to remove the ModuleNotFoundError: No module named 'krunk-
copy' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'sh-copy'ModuleNotFoundError: No module named 'sh-
copy' Hi,
My Python...-
copy'
How to remove the ModuleNotFoundError: No module named 'sh-
copy... to install padas library.
You can install sh-
copy python with following command
ModuleNotFoundError: No module named 'sh-copy'ModuleNotFoundError: No module named 'sh-
copy' Hi,
My Python...-
copy'
How to remove the ModuleNotFoundError: No module named 'sh-
copy... to install padas library.
You can install sh-
copy python with following command
ModuleNotFoundError: No module named 'temp-copy'ModuleNotFoundError: No module named 'temp-
copy' Hi,
My Python... 'temp-
copy'
How to remove the ModuleNotFoundError: No module named 'temp-
copy' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'temp-copy'ModuleNotFoundError: No module named 'temp-
copy' Hi,
My Python... 'temp-
copy'
How to remove the ModuleNotFoundError: No module named 'temp-
copy' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'temp-copy'ModuleNotFoundError: No module named 'temp-
copy' Hi,
My Python... 'temp-
copy'
How to remove the ModuleNotFoundError: No module named 'temp-
copy' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'temp-copy'ModuleNotFoundError: No module named 'temp-
copy' Hi,
My Python... 'temp-
copy'
How to remove the ModuleNotFoundError: No module named 'temp-
copy' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'wet_copy'ModuleNotFoundError: No module named 'wet_
copy' Hi,
My Python..._
copy'
How to remove the ModuleNotFoundError: No module named 'wet_
copy... to install padas library.
You can install wet_
copy python with following
ModuleNotFoundError: No module named 'wet_copy'ModuleNotFoundError: No module named 'wet_
copy' Hi,
My Python..._
copy'
How to remove the ModuleNotFoundError: No module named 'wet_
copy... to install padas library.
You can install wet_
copy python with following
ModuleNotFoundError: No module named 'copy-pase'ModuleNotFoundError: No module named '
copy-pase' Hi,
My Python... '
copy-pase'
How to remove the ModuleNotFoundError: No module named '
copy... have to install padas library.
You can install
copy-pase python with following
copy string to string objective ccopy string to string objective c How to
copy a value of NSString to another string in Objective C? I have to different views and i am will to show the NSString value in both of them.
Thanks
Java Copy file example Copy one file into another
Copy one file into another
In this section, you will learn how to
copy content of one file into another
file. We
Creating a Copy of a Collection Creating a
Copy of a Collection
... and then
copy the collection. The copied collection contains the reference... a collection (list) and
copy for the duplicate collection with content
Copy Table in a MySQL Database
Copy Table in a MySQL Database
In this section, you will learn to
copy one table to another... you in copying one
table to another in a same MySQL database.
To
copy any table
How to copy a fileHow to
copy a file
In this section, you will learn how to
copy a file using Java IO library. For
this, we have declared a function called copyfile() which...;}
}
The above code makes a
copy of the file
Copy one file into anotherCopy one file into another
In this section, you will learn how to
copy content of one file into another
file. We will perform this operation by using the read & write methods of
BufferedWriter class.
Given below example will give
Copy Directory or File in Java Copy Directory in Java
... how to
copy the directory and files into a new directory.
In this program, you... srcPath, File dstPath):
The copyDirectory() method
is used to
copy contents
How to copy a file in javaHow to
copy a file in java
In this section you will learn about how to
copy... direct way to
copy a file.
What we can do is, read a content of one...; FileUtils.copyFile(source file , destinationfile),
which allows you to
copy a file
Copy file in php, How to copy file in php, PHP copy file
Learn How to
copy file in php. The PHP
copy file example explained here...;
In the following example we will show you how to use of
copy() function in php. The
copy function in PHP is used to
copy the content of one file into another