I know this has probably been ask one billion times, but I am still finding it difficult in getting a straight forward answer.
Where do you put the code under? Can you just add it through the GUI builder-if so how? Or do you have to 'manually' add it in the code? If so do you put it under public class or just class? How to you write it?
Though I would personally prefer if there was a way to add the photo through the GUI builder.
Also, if I added an imagine to a JLabel, would it be possible for me to set it as a background so all the other JLabels or Buttons etc in the GUI is overlapping the picture?
Netbeans version 6.9.1
In Netbeans it is a little bit difficult to do this but still it could be done (not as easy as VS). You just have to follow the following steps:
Create the new JPanel object using the wizard
Go to the Source mode and paste the following text
-
public NewJPanel() { //this is the contsructor , so change the name apropriately
try {
image = ImageIO.read(new File("c:\\1.png")); //path to your image
} catch (IOException ex) {
}
initComponents();
}
private BufferedImage image;
#Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, null); //image drawing properties
}
Import all apropriate libs
Save the NewJPanel file.
Now go to your JFrame and drag and drop a Panel Object from the Swing Container list
Right click on the new jPanel object and select Customize Code from the menu
In the Code Customizer box select Custom creation and enter the following code. see image below
jPanel1 = new NewJPanel();
By doing this you replace the standard JPanel object with the one you created in the first steps
Click ok and then run your JFrame. You should see the image inside the JPanel now
PS: My Netbeans version is 7.2.1
Related
Most of program is using JFrames throughout the application for all the different windows that can appear. However, I have to play an instructional video for the user inside a JFrame. I couldn't find a way to do this, so I had to make a JavaFX program. Is there a way to get directly from one of my JFrames to the JavaFX window?
I've been using syntax like this to open up other JFrame:
dispose();
paths pths = new paths();
pths.setVisible(true);
However, when trying to open up the JavaFX using the above code, I get errors. I also can't create a new JavaFX inside an already existing project.
I am not sure to understand your problem but in order to create a new frame in JavaFX. You have to create a new class with a new stage. Let's say you create a new class "newFrame" with the code below.
public void show(Stage stage){
//define your root
double width = 200;
double height = 200;
Scene scene = new Scene(root, width , height);
stage.show();
}
You can show the new frame by using :
newFrame NT = new newFrame();
NT.show();
I am trying to remove borders of the portlet as well as the panel.
Below is my code snippet,
public class TestViewImpl extends ViewImpl implements TestViewPresenter.MyView{
private PortalLayoutContainer portal;
#Inject
public TestViewImpl (){
portal = new PortalLayoutContainer(1);
vp = new VerticalLayoutContainer();
portal.getElement().getStyle().setBackgroundColor("white");
portal.setColumnWidth(0, 1);
portal.setBorders(false);
ContentPanel portlet = new Portlet();
portlet.getHeader().setVisible(false);
portlet.setBorders(false);
portlet.setBodyBorder(false);
portlet.add(vp);
portlet.setResize(true);
portlet.setBodyStyle("backgroundColor:white;");
portal.add(portlet, 0);
But somehow the border is always visible.How do I remove the border ? Please help.
Thanks in advance
With that code I can get the borders to disappear (with small alterations to container instantiation). Where are those containers coming from? Are you using UI Binder, if so could you post that code as well.
The blue section that is left is the background from the header. (Hide header hides the text)
If you really need to remove the outline border (which is a background image actually), you can try something like this:
Element e = portlet.getElement().getFirstChildElement();
e.getStyle().setBorderWidth(0, Unit.PX);
Here is the screenshot of the result:
It's not going to be easy, but this is the only way (from what I know and tried already), you going to need developer tools on browser (i.e. firebug) to do inspection, and predict what element to get and what attribute to remove. The code I provide above are just example how we can remove the top outline border, and for the rest you can tried it by yourself. Goodluck :-)
I tried to apply this solution to my problem, but it doesn't work. I've got a class which extends Wizard and implements INewWizard. It's called by an Activator-class. I don't have wizardDialog anywhere so I unsuccessfully tried it like this:
public SeeTableScreenWizard()
{
super();
WizardDialog wizardDialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), this);
wizardDialog.setPageSize(800, 400);
setNeedsProgressMonitor(true);
}
The reason why i need it is the following: one of the pages has a org.eclipse.swt.widgets.List which has many entries. Its doesn't have any consequences until i run the wizard for the second time. Its height is being set to the screen height, i suppose because it tries to set the size to that big page created at the first run.
Give me some clues please.
I have created two gtkmm button and added to HBox object. I called pack_end, and maintained the size as 21,20. But, the sizes are not maintained. Here is the code i have written and the window that i got while running the program.
Note: MYWindow is subclass of Gtk::Window
void MYWindow::customizeTitleBar()
{
//create a vertical box
Gtk::VBox *vBox = new Gtk::VBox(FALSE,0);
//create a horizontal box
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0);
hBox->set_border_width(5);
//create title bar image
Gtk::Image *titleBarImage = new Gtk::Image("src/WindowTitleBar.png");
titleBarImage->set_alignment(Gtk::ALIGN_LEFT);
// hBox->pack_start(*titleBarImage,Gtk::PACK_EXPAND_WIDGET,0);
//create cloze button for window
mButtonClose = new Gtk::Button;
(*mButtonClose).set_size_request(21,20);
Gtk::Image *mImage = new Gtk::Image("src/Maximize.jpeg");
(*mButtonClose).add(*mImage);
(*mButtonClose).set_image_position(Gtk::POS_TOP);
// connecting close window function when cliked on close button
//(*mButtonClose).signal_clicked().connect( sigc::mem_fun(this, &MYWindow::closeWindow));
hBox->pack_end(*mButtonClose,Gtk::PACK_EXPAND_WIDGET,0);
Gtk::Button * mBtton = new Gtk::Button;
mBtton->set_size_request(21,20);
Gtk::Image *img = new Gtk::Image("src/Maximize.jpeg");
mBtton->add(*img);
mBtton->set_image_position(Gtk::POS_TOP);
hBox->pack_end(*mBtton,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBox);
//drawing area box
Gtk::HBox *hBoxDrawingArea = new Gtk::HBox;
Gtk::DrawingArea *mDrawingArea = new Gtk::DrawingArea;
hBoxDrawingArea->pack_start(*mDrawingArea,Gtk::PACK_EXPAND_WIDGET,0);
vBox->add(*hBoxDrawingArea);
//status bar hBox
Gtk::HBox *hBoxStatusBar = new Gtk::HBox;
vBox->add(*hBoxStatusBar);
this->add(*vBox);
this->show_all();
}
I am not yet a gtk expert (but I'm learning), here's one thing you can try, which is what I've been doing.
Make a little standalone project using glade. Glade makes it really easy to screw around with all the packing settings so you can immediately see the effects of your changes.
I think in the case of resizing the window, you'll have to save the glade file and run your program (using gtkbuilder to render the glade file) and manually resize the window to see the effect, but once you make the standalone project, you can use it for other gtk testing.
And if you're like me, you'll get swayed by the wonderfulness that is glade and build your whole system that way.
But basically, it sounds like a packing issue, because I've got buttons that don't resize all over the place.
As for not moving, I'm not sure you can do that, but again I'm not an expert. I think you should be able to pin the size of some if not all of the hbox pieces so that the button inside them will not move, but I'm not sure what happens if you don't have any hbox parts that can't be variably sized to take up the slack when you grow the window.
Again, sounds like something fun to try in glade. :-)
I think you pack to FALSE , Maybe this is the problem :
Gtk::HBox *hBox = new Gtk::HBox(TRUE,0)
I use python gtk with something like this:
box1.pack_start(box2,False)
I am trying to draw some shapes (boxed ans arrows) into, i.e., "over" the text in an eclipse editor. To get started, I wrote the following code:
IWorkbenchPage activePage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
final Shell shell2 = activePage.getActiveEditor().getSite().getShell();
shell2.addPaintListener(new PaintListener(){
public void paintControl(PaintEvent e){
Rectangle clientArea = shell2.getClientArea();
e.gc.drawLine(0,0,clientArea.width,clientArea.height);
}
});
The problem with this code is twofold: (1) The line is drawn not across the editor but across the entire workbench, i.e., Eclipse window, and (2) the line is drawn behind (!) all other controls like toolbars and editors. This causes the line to be almost invisible: it only shows at some pixels between other controls.
How can I draw a line across a control like a text editor in Eclipse?
The problem that you have is that you are getting the Shell, not the actual component for the editor. The Shell is the whole window where Eclipse is being shown.
I think the only solution is to create your own Editor implementation, and then in the createPartControl() method you can create a text area and then add the paint listener to it.
You can get started with:
http://www.realsolve.co.uk/site/tech/jface-text.php
And then, looking at the source code of AbstractTextEditor, you can find the "real" SWT component that you want to draw to. You would need to override the method that creates the UI components, copy the original code and add your custom painting.
I'm not sure if it works, but you need to extend the TextEditor:
public class MyEditor extends TextEditor {
protected StyledText createTextWidget(Composite parent, int styles) {
StyledText widget = super.createTextWidget( parent, styles );
widget.addPaintListener( <yourPaintlistener> );
return widget;
}
}
That should at least get you the basic text-drawing control of the editor. Still, it's a PITA to work with these classes, as it is very internal stuff from eclipse, and neither documented nor really extensible.
Good luck with that :)