Here is how I show the Jasper report in swing applications.
JasperViewer.viewReport(jasperPrint, true);
Then when the report is viewed, the report viewer's title is "Jasper Viewer" . I want to change it and set my own title name. My other question is how to directly send the report to the print without viewing.Please give any sample code.Thank you
What I normally do is :
JasperViewer jv = new JasperViewer(jasperPrint, false);
jv.setTitle("Report-Title");
jv.setVisible(true);
This works because, JasperViewer is a JFrame -
public class JasperViewer extends JFrame{
//...
}
JasperViewer.viewReport(...)is a wrapper class that creates and shows a JasperViewer JFrame with a JRViewer panel.
Using this method you can't access the underlying JFrame, so you can't change the frame title.
You can try to create your own JasperViewer frame using the public constructor, and then set the title using the setTitle(...) method.
Another and recommended approach is to create a custom JDialog with a JRViewer panel.
To print your report without viewing:
final JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();
Related
When I set the logo for my java plugin, the logo of other windows of eclipse are changed.
I have a class which extends Wizard and implements IObjectActionDelegate. Then, I have override the run function and write the below code in it.
wizard = new StartWizard();
dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
Bundle bundle = Platform.getBundle("Plugin");
URL url = FileLocator.find(bundle, new Path("icon/Logo.png"), null);
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
WizardDialog.setDefaultImage(image);
I have read the solution set forth to the similar post on Only changing the logo of special plugin. The problem is that I have extended Wizard and cannot extend WizardDialog instead.
Since you are creating WizardDialog yourself you can actually extend that class if you want.
In a Wizard you can get the current Shell by calling:
Shell shell = getContainer().getShell();
shell.setImage(your image);
It looks like the wizard addPages method would be suitable for this code.
Well I was wondering if I could make an icon image for a JFrame. I do know its posible, because, let me say, I am NOT digging the java logo.
Well if I just hava to use a Frame object I will.
Can someone tell me, I know its possible!
Use an ImageIcon.
ImageIcon icon = new ImageIcon( pathToIcon );
yourFrame.setIconImage(icon.getImage());
Good Luck!
First, you have to have an image file on your computer. It can be named anything. For this example, we will call this one "pic.jpg".
Next, you need to include it in the files that your application is using. For example, if you're using NetBeans, you simply click on "Files" in the left hand side of the IDE (not File as in the menu, mind you). Drag the picture's file over to the folder that houses the main package. This will include it for available use in the code.
Inside the method where you define the JFrame, you can create an image like this:
Image frameImage = new ImageIcon("pic.jpg").getImage();
You can now set it as the IconImage for the frame like this:
JFrame frame = new JFrame("Title");
frame.setIconImage(frameImage);
Hope that's helpful.
Note: the reason that the Image object has to be created like this is because Image is abstract and cannot be instantiated by saying new Image();
Props to you, btw, kid. I wish I would have started learning programming when I was your age. Keep at it!
You can do the following.
public Test {
public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.setIconImage(new ImageIcon(Test.class.getResource("image.png"));
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
frame.setSize(100, 100);
//other stuffs....
}
}
I have created a small report using jasper reports and I previewed it using the jasper viewer as below,
con = JDBCConnectionPool.getInstance().checkOut();
String fileName = getClass().getClassLoader().getResource("com/bio/ofm/mnu/views/reports/jasperReports/repAuditReport.jrxml").getFile();
JasperReport report = JasperCompileManager.compileReport(fileName);
JasperPrint print = JasperFillManager.fillReport(report, null, con);
JasperViewer viewer = new JasperViewer(print);
viewer.setVisible(true);
But I need to show this report in a JPanel so, I tried as,
JasperViewer.setDefaultLookAndFeelDecorated(true);
JRViewer jrv = new JRViewer(print);
jrv.setPreferredSize(new Dimension(getSize()));
JScrollPane reportScroll = new JScrollPane(jrv);
panel1.add(reportScroll);
but the report is not showing as I expected, please explain what is the correct way to add a jasper preview in to a JPanel.
JasperViewer extends JFrame, and you don't want to add a JFrame to a JPanel. You could perhaps add the JasperViewer's contentPane to the JPanel. The other issues I've discussed in a comment still remain unresolved:
What layout manager is panel1 using? Are you adding the JScrollPane to the JPanel after the GUI has been displayed? If so, do you call revalidate() and repaint() on the JPanel after the addition?
this my code and it works
JRViewer jr=new JRViewer(print);
jPanel1.setLayout(new BorderLayout());
jPanel1.repaint();
jPanel1.add(jr);
jPanel1.revalidate();
Currently I have a very basic file viewer working as follows :
- in JOptionPane I browse for files, and set some variables to display (colors, line connecting etc)
- previous windows loads a frame with drawn points
alt text http://img190.imageshack.us/img190/4443/104bu.jpg
Code :
http://paste.pocoo.org/show/220066/
Now I'd like to throw it into one window, with JMenu for selecting files and changing display parameters. How to get started ? Should I rewrite everything to JDialog ?
alt text http://img684.imageshack.us/img684/5264/lab10db.jpg
If you want the JOPtionPane as a child of the main JFrame, then add it as a child. Of course it will then cover your dots. Hence you will have to not draw your dots directly in the content pane of the main JFrame, but rather in a new JPanel that you have also added to the JFRame's content pane. Let me know if I've understood the question whatsoever.
Here's some code for how I see the setup (I'm leaving the layout problem out of this, partly because it depends on what you want to see):
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(new Dimension(400,400));
frame.getContentPane().add(new JOptionPane());
JPanel canvasForDots = new JPanel();
frame.getContentPane().add(canvasForDots);
You might also like to look at How to Use Tool Bars and How to Use Menus. ImageApp is a typical implementation that associates menu items with the corresponding Action instances.
private class ClearAction extends AbstractAction {…}
private class ImageOpenAction extends AbstractAction {}
private Action openAction = new ImageOpenAction("Open");
private Action clearAction = new ClearAction("Clear");
…
JMenu menu = new JMenu("File");
menu.add(new JMenuItem(openAction));
menu.add(new JMenuItem(clearAction));
This related example adds the file chooser directly to the main frame. Here's a more elaborate example of connecting lines and shapes using the same principles.
i am trying to update the title of a JInternalFrame component in my Java Project.
The component is an instance of my ImageFrame class which extends JInternalFrame, and in my code I call a setter method in my ImageFrame class which updates the title attribute. I ran a Unit test and know that the attribute is updating properly, but I can't figure out how to refresh the component to show the new title.
Any Ideas?
FYI: I was unable to get .repaint() to do the trick.
Here's the Code:
File selectedFile = fileChooser.getSelectedFile(); // Gets File selected in JFileChooser
try {
ImageReadWrite.write(img, selectedFile); // Writes Image Data to a File
frame.setFilePath(selectedFile.getAbsolutePath()); // Changes File Location Attribute in Instance Of ImageFrame
frame.setFileName(selectedFile.getName()); // Changes Window Title Attribute
//frame.??
}
catch (Exception event) {
event.printStackTrace();
}
so what I need here is to know what I should add to make the component update with the new title
You could try by replacing:
frame.setFileName(selectedFile.getName());
with
frame.setTitle(selectedFile.getName());
I don't know your code, but setFileName is not part of JInternalFrame public interface.
Probably you added that method, probably not. Try my suggestion and see if that helps.