Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37954
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Can you execute a command in Eclipse? |
| Date | 2018-01-17 13:08 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <p3o3f6$1h52$1@gioia.aioe.org> (permalink) |
| References | <6aa5f167-870c-4084-bfb2-e5cf03a0dbd6@googlegroups.com> |
On 1/17/2018 10:13 AM, Eric Douglas wrote:
> Is there a place to execute a command, like say I'm running a Java
> test with a JFrame can I just manually set the title of it without
> ending the JVM and starting over?
I think this will be difficult as Eclipse and your application
are running in two different JVM's.
Alternative approach:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.StringReader;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import bsh.EvalError;
import bsh.Interpreter;
public class GUIUtil {
public static void hack(JFrame origframe) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
JFrame newframe = new JFrame() {
private static final long serialVersionUID = 1L;
private JTextField cmd;
private JButton btn;
{
setTitle("Execute commands");
this.setPreferredSize(new Dimension(600, 75));
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new
JLabel("Command:"), BorderLayout.WEST);
cmd = new JTextField();
getContentPane().add(cmd, BorderLayout.CENTER);
btn = new JButton("Execute");
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent
e) {
try {
ByteArrayOutputStream baos =
new ByteArrayOutputStream();
PrintStream ps = new
PrintStream(baos);
Interpreter i = new
Interpreter(new StringReader(""), ps, ps, false);
i.set("f", origframe);
i.eval(cmd.getText());
i.run();
byte[] msgbuf =
baos.toByteArray();
if(msgbuf.length > 0) {
JOptionPane.showMessageDialog(null, new String(msgbuf));
}
} catch (EvalError e1) {
e1.printStackTrace();
}
}
});
getContentPane().add(btn, BorderLayout.EAST);
pack();
}
};
newframe.setVisible(true);
} catch(Exception ex) {
ex.printStackTrace();
}
}
});
}
}
and in your application:
GUIUtil.hack(yourjframeinstance);
and then in the extra windows simply enter:
f.setTitle("Bla");
and click execute.
Requires BeanShell present.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can you execute a command in Eclipse? Eric Douglas <e.d.programmer@gmail.com> - 2018-01-17 07:13 -0800
Re: Can you execute a command in Eclipse? Arne Vajhøj <arne@vajhoej.dk> - 2018-01-17 13:08 -0500
Re: Can you execute a command in Eclipse? Eric Douglas <e.d.programmer@gmail.com> - 2018-01-17 13:47 -0800
Re: Can you execute a command in Eclipse? Arne Vajhøj <arne@vajhoej.dk> - 2018-01-17 19:18 -0500
csiph-web