How to embed a jframe in an eclipse view [duplicate] - swt

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Any way to embed a Swing JFrame in the AWT Frame from the SWT_AWT bridge?
I have an RCP application with many views.
I have a class which extends JPanel and draws some things.
Is there any way to embed this class to be shown inside a view?

Composite swtAwtComponent = new Composite(parent, SWT.EMBEDDED);
java.awt.Frame frame = SWT_AWT.new_Frame( swtAwtComponent );
javax.swing.JPanel panel = new javax.swing.JPanel( );
frame.add(panel);
frame.add(jFrameClass)

Related

Howto set the resize control of a com.smartgwt.client.widgets.Window to the top

Is it possible to set the resize control of an com.smartgwt.client.widgets.Window not only to the bottom and the right but also to the top and the left?
The window Instance is created as follows:
Window window = new Window();
window.setAutoSize(true);
window.setTitle(title);
window.setCanDragReposition(true);
window.setCanDragResize(true);
SmartGWT 6 is in use.
With help of the Isomorphic guys, the solution is as simple as follows:
// https://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/types/EdgeName.html
window.setResizeFrom(EdgeName.L, EdgeName.T);

Eclipse PDE: How to add buttons to a view?

I have created a simple view, but it would be nice to add buttons to it. For example, I drew two blue buttons into the view below. Is there a way to add similar buttons to my Eclipse view? I know that I can add a pulldown menu, from this question, but buttons are preferable.
My example below is just a demonstration - the location/size/color of the buttons does not matter as long as the buttons are inside the view.
In case you are using SWT:
For a start you could install WindowBuilder. It lets you work on the UI level without caring to much about implementation. The generated code however is not layed out in the way that you can work with, when you are creating views with more than a few buttons.
The implementation depends on your Eclipse version.
In the old Eclipse 3.x, a Button could be set up by Overriding the method createPartControl:
#Override
public void createPartControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout(1, false));
Button btnMybutton = new Button(container, SWT.NONE);
btnMybutton.setBounds(0, 10, 75, 25);
btnMybutton.setText("MyButton");
//do anything else here
}
If you are familiar with other UI Frameworks and don't like SWT, you might as well switch to e.g. Vaadin or JavaFX. There's a blog articleabout changing the renderer of your application.

How to Implement the help button with question mark icon on the WizardDialog [duplicate]

This question already has an answer here:
Can't put content behind SWT Wizard Help Button
(1 answer)
Closed 6 years ago.
I have implemented a Wizard and WizardPage. I noticed that it has a help button with question mark icon. I would like to open a browser internal/external with a static url(www.stackoverflow.com). I have tried a few things but I couldn't find what gets executed when the button is clicked.
I have implemented the HelpListener on both WIZARD & WIZARDPAGE; but could not get the method to be invoked when I click on the button.
public void helpRequested(HelpEvent e) {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL("http://www.stackoverflow.com"));
}
In the WIZARD constructor I have setHelpAvailable(true); and it gives me the Help button with the text.
I also tried the HandleEvent in the WIZARDPAGE with SWT.Help event type but again nothing happened.
I am not sure if & how I can add listener to this button? and How I could implement to open a browser by clicking on this button.
Please advice.
Thanks in advance.
Each org.eclipse.jface.wizard.WizardPage can implement performHelp(), there you should be able to open a browser with your help.

Canvas J2mE list form

How can I create create a form/list using canvas and add TextField to it?
public void paint(Graphics g){
g.setColor(44,255,44);
g.fillRect(0,0, getWidth (), getHeight ());
form = new Form("");
form.append("acfascca");
}
See this article Drawing TextField on Canvas j2me. But i feel If you are starting new project means you can go with LWUIT Framework. Also see this discussion.
Canvas is a low level API, hence I don't think it supports adding of Form to it.

Creating a JApplet (swing based applet) with netbeans?

I am starting to learn Java a little after long time. And learning Netbeans 7.0.
I just want to make sure I am doing this ok.
I basically need to make an applet, but not having it AWT based, but instead Swing based.
So I need to extend JApplet, not Applet. I understand in swing draws on a Jpanel instead of awt canvas (or Panel). And so I read on a web site that one needs to override PaintComponent() instead of overrriding paint() as the case with awt applet?
I need to make a very simple applet, say with one button, when I click on it, I want to draw a graphics, say a line or circle, and have the output go to an area below the button.
This is what I did
File->New Project
Select Java and from Projects, select "Java Application"
make sure to Un-check the "create Main class", and click Finish
File->New file
Select "Swing GUI Forms" from under the catagories panel
From the "File types", Select Japplet Form,Next and Finish
From the palette, from Swing Controls, select Button and lay it on the from
Now the tricky part. I need an area to draw on, right? So I from palette, I select, from Swing containers, a "Panel", and lay it on the form, resize it as needed. Do, now I have this:
Am I on the right track so far? Now I open the source file, and I see the init() method.
Now is where I need little help. Not sure what the code I need to insert to just draw a line to the JPanel I just added. I know I need to insert it here:
I tried the "insert Code" feature, and select override, but do not see PaintComponent()?
I know how to do it in swt applet, just add a paint(Graphics g) method. But when I do this, the graphics do not draw inside the Jpanel area. Basically, how do I tell it to draw something to a specific JPanel area?
If someone just tell me what code I need to insert there to draw a line or any graphics2D object to display on that JPanel I added below the bottom, that will great.
thanks,
--Nasser
EDIT 1:
Just a clarrification: If I add this function to paint on the Jpanel:
public void paint(Graphics g)
{
super.paint(g);
g.drawString(....);
}
Then the output does show ok, but it over the main Japnel. And can hide the button and any other UI components are there.
I need the paint output to go to a specific Jpanel which I added earlier below the button. To this one
private javax.swing.JPanel jPanel1;
So, my question is, how to draw/paint to the above object and not to the main Jpanel?
EDIT 2:
I tried just to change the JPanel background color, and it is not working. Here is the code.
I also tried JpanelForm instead of JApplet Form. Can one use JFrame form to make an applet? Since that requires a main() it does not seem possible.
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics;
public class NewJApplet extends javax.swing.JApplet
{
/** Initializes the applet NewJApplet */
public void init()
{
jPanel1 = new JPanel();
try
{
java.awt.EventQueue.invokeAndWait(new Runnable()
{
public void run()
{
initComponents();
}
});
} catch (Exception ex)
{
ex.printStackTrace();
}
}
private void initComponents() {...}
//--------- ADDED THIS
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
Rectangle rect=new Rectangle(4,4);
jPanel1.setBackground(Color.RED);
}
//---------------
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
NetBeans "does" support JApplet. After creating a new project, rt-click on the project's package in "projects" pane which is to the left of your coding area and choose New -> JApplet
netbeans does not support making JApplets, only applets. Use standard text editor to design the JApplet interface then compile the source code using javac.
I went through the same thing just now, you just need to take the package name out from the file and just compile it. You will get a message in netbeans that the applet is not initialized which is ok, just go to the source folder where .class files are stored you will find multiple NewJApplet.class files, You will see some with a $ sign in them too.
Copy all the .class files put it together with the html file and that is it. View your JApplet created using the form on the browser. Makes creating anything with java so much fun.