private void copier(JTextPane txt) { try { String str=txt.getText(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection strSel = new StringSelection(str); clipboard.setContents(strSel, null); }catch(Exception err) { err.printStackTrace(); } } private void coller(JTextPane txt) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); String text=""; try { text = (String) clipboard.getData(DataFlavor.stringFlavor); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } txt.setText(text); } |
A Voir sur le même Sujet
-
Java: Copier et Coller sur un JTextArea
{filelink=23} private void copier(JTextArea txt) { try { String str=txt.getText(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection strSel = new StringSelection(str); clipboard.setContents(strSel, null); …
-
Java: Copier et Coller sur un JTextField
{filelink=23} private void copy(JTextField txt) { try { String str=txt.getText(); Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection strSel = new StringSelection(str); clipboard.setContents(strSel, null); …
-
Java: Copier un document XML
{filelink=8372} /***** Code de MesExemples.com *******/ /** * @(#)CopieXMLDoc.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public …
-
Java NIO: Copier un fichier
{filelink=22} import java.io.*; import java.nio.*; import java.nio.channels.*; public class NIOCopier { public static void main(String[] args) throws IOException { String in_File=”c:/test.txt”; String out_File=”c:/test2.txt”; copier(in_File,out_File); } …
-
Wildcard: Copier le contenu d’une liste dans une autre
{filelink=12227} import java.util.ArrayList; import java.util.List; import java.util.Arrays; public class Generic_Wildcard { // La fonction copie une liste d’objet dans une autre public static void copier(List
-
Java: Copier le contenu d’un Fichier dans un autre
{filelink=23} /** * @(#)JavaFileCopier.java * * * @author * @version 1.00 2013/8/24 */ import java.io.*; import java.nio.*; import java.nio.channels.*; public class JavaFileCopier { public JavaFileCopier() …
-
Collection: Copier les éléments d’une ArrayList dans une autre
{filelink=4856} import java.util.ArrayList; import java.util.Collections; public class Ex_ArrayL { public static void main(String[] args) { ArrayList array_L1 = new ArrayList(); array_L1.add(“1”); array_L1.add(“2”); array_L1.add(“3”); ArrayList array_L2 …
-
Java: Copier les sous-arborescences de nœuds d’un document DOM vers un autre
{filelink=8547} /***** Code de MesExemples.com *******/ /** * @(#)XMLSubTreeFromDocToDoc.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/5 */ import java.io.File; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import …
-
Copier les éléments d’un ‘ArrayList’ dans un Vecteur
{filelink=4855} import java.util.ArrayList; import java.util.Collections; import java.util.Vector; public class ArrayListToVec { public static void main(String[] args) { // Création d’un ArrayList ArrayList arrayList = new …
-
Exemple d’utilisation de ‘Arrays.copyof’ pour copier un tableau
{filelink=820} import java.util.Arrays; public class ExempleArrayCopy { public static void main(String args[]) { System.out.printf(“Valeur Initiale (Tableau original)\t%s%n”, Arrays.toString(args)); // Copier le contenu du tableau “args” …
-
Copier le contenu d’un Stream dans un Autre
{filelink=4621} import java.io.*; class CopierStream { /** * Copier un Stream dans un autre * On utilise les classes abstraites * ‘InputStream’ et ‘OutputStream’ * …
-
Java 8: Exemple d’utilisation des Expressions lambda
En prélude au lancement officiel de OpenJdk avec Java SE 8, Nous introduisons ici l’utilisation d’une fonctionnalité de Java8 Qui va beaucoup plaire au développeurs …
-
la boucle Do while »”
{filelink=4628} public class DoWhileDemo { public static void main(String[] args) { String meCopier = “Copier ce text jusqu’à ce que vous trouvez la lettre ‘v’.”; …
-
Démonstration d’une boucle avec while
{filelink=4627} public class WhileDemo { public static void main(String[] args) { String meCopier = “Copier ce text jusqu’� ce que vous trouvez la lettre v”; …
-
Java: Copier une arborescence source vers une une arborescnce destination*
{filelink=8415} /***** Code de MesExemples.com *******/ import org.w3c.dom.Attr;import org.w3c.dom.DOMException;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import com.sun.org.apache.xerces.internal.dom.AttrImpl;import com.sun.org.apache.xerces.internal.dom.DocumentImpl;/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the “License”); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an “AS IS” BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */public class Main { /** * Copies the source tree into the specified place in a destination * tree. The source node and its children are appended as children * of the destination node. * * Note: This is an iterative implementation. */ public static void copyInto(Node src, Node dest) throws DOMException { // get node factory Document factory = dest.getOwnerDocument(); boolean domimpl = factory instanceof DocumentImpl; // placement variables Node start = src; Node parent = src; Node place = src; // traverse source tree while (place != null) { // copy this node Node node = null; int type = place.getNodeType(); switch (type) { case Node.CDATA_SECTION_NODE: { node = factory.createCDATASection(place.getNodeValue()); break; } case Node.COMMENT_NODE: { node = factory.createComment(place.getNodeValue()); break; } case Node.ELEMENT_NODE: { Element element = factory.createElement(place.getNodeName()); node = element; NamedNodeMap attrs = place.getAttributes(); int attrCount = attrs.getLength(); for (int i = 0; i
Cet article Java: Copier et Coller sur un JTextPane est apparu en premier sur .