I try to create a button that copy in the clipboard a String and then user can paste it.
I can do it when I do my test in local, but when I deploy the application on a server, nothing is saved in clipboard after an user click on button.
Here's my code :
public void clipboard() {
try {
StringSelection stringSelection = new StringSelection("test");
Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
clpbrd.setContents(stringSelection, null);
} catch (Throwable e) {
e.printStackTrace();
}
}
How can I do it ?
Related
Desktop desktop = Desktop.getDesktop();
File sitetxt = new File(System.getProperty("user.dir") + File.separator + "site.txt");
MenuItem settings = new MenuItem("Settings");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
desktop.open(sitetxt);
} catch (IOException e1) {
System.out.println("site.txt not found.");
e1.printStackTrace();
}
}
});
popup.add(settings);
trayIcon.setPopupMenu(popup);
I'm trying to open a text file when the user clicks "Settings" from the right click menu of the system tray icon. The default text editor is set to Notepad. There is another menu item called "Exit" but it works fine.
How to get the text in a Text Area to be saved to a text file when a button is clicked?
I have implemented the GUI and when the btnContinue button is clicked I want the content of txtOrder to be saved to a text file in notepad.
I'm not a pro programmer in Java so pls correct me if I'm wrong, but I would try this:
FileWriter fw = null;
try
{
fw = new FileWriter("Output.txt",true);
fw.write(txtOrder.getText())
//textArea.write(fw);
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
if (fw!=null)
{
fw.close();
}
}
i am new to eclipse plugin development. i created a plugin which loads a unicode saved text file from the folder & displays it on a dialog & also setting it for the Label. If it is, in an English Language, everything is working fine. But if i try to load any other language text, it is displaying empty. How can i get through this.
Here is some code on how i am displaying it on dialog:
Shell shell = Display.getCurrent().getActiveShell();
// Loading the file by creating the assets folder & Temp.txt file inside
// Eclipse Plugin
URL url = FileLocator.find(bundle, new Path("assets/Temp.txt"), null);
URL fileUrl = null;
try {
fileUrl = FileLocator.toFileURL(url);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
File file = new File(fileUrl.getPath());
String Message = "";
try {
if (file.exists()) {
BufferedReader in = new BufferedReader(
new FileReader(file));
String str;
while ((str = in.readLine()) != null) {
if (str.contains(LanguageSelected)) {
System.out.println(str);
Message = Message + "\n" + str;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
// Creating the dialog
Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
...
// Adding Label to dialog
Label LabelMessage = new Label(dialog, SWT.LEFT);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 6;
// Adding Message to the dialog
LabelMessage.setLayoutData(data);
LabelMessage.setBackground(new Color(null, 255, 255, 255)); // White
LabelMessage.setText(Message);
In your launch configuration, make sure you are setting the -nl parameter to the language you want to display. See http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html for information.
I'm making a little program that when a jButton is clicked, it opens the downloads folder from the file explorer. I have the button set up, I'm just having troubles getting the folder open.
Here is my code.
private void downloadsActionPerformed(java.awt.event.ActionEvent evt) {
String download = System.getenv("downloads");
File downloadsDir = new File(download);
try {
Desktop.getDesktop().open(downloadsDir);
} catch (IOException ex) {
Logger.getLogger(GettingFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
Am using codename one to capture the video and upload it to Vimeo.
But I get errors when I click the button. What am I doing wrong ?
I get below error when the method is called.
I have a camera
java.lang.NullPointerException
at userclasses.StateMachine$1.actionPerformed(StateMachine.java:63)
protected void onMain_Button1Action(Component c, ActionEvent event) {
Capture.captureVideo(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(Capture.hasCamera()){
System.out.println("I have a camera");
}else{
System.out.println("I don't have a camera");
}
try {
String path = (String) evt.getSource();
Log.p("Path->" + path);
Vimeo.MyVimeo(path);
is.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
The event can be null if the operation is canceled.
You are not meant to select a file, The capture class is for capturing media files from the device. It brings out FileChooser if you are using the emulator, therefore test it on a device and see how it works.