i am creating jasper report for view the student details. i have a textfield if the enter correct student id relavent student details display on the jsper report below. i called the jsper report inside the jpanel.
if i enter first time student id 3 it displayed result success then if i enter the second time student id 4 the same result shown. i don't know why.
HashMap a = new HashMap();
a.put("id", txtno.getText());
try {
JasperDesign jdesign = JRXmlLoader.load("C:\\Users\\kobinath\\Documents\\NetBeansProjects\\JavaApplication138\\src\\report1.jrxml");
JasperReport jreport = JasperCompileManager.compileReport(jdesign);
JasperPrint jprint = JasperFillManager.fillReport(jreport, a, con);
// JasperViewer.viewReport(jprint);
JRViewer vw=new JRViewer(jprint);
jPanel1.setLayout(new BorderLayout());
jPanel1.repaint();
jPanel1.add(vw);
jPanel1.revalidate();
} catch (JRException ex) {
}
I think that revalidate() alone isn't enough to refresh the panel. You may reference to this link to make sure that repaint() is better to be called.
I hope this helps you solve your problem.
P.S. You can swap the two lines before the last line.
Related
I have an activity where I create Tablerow programatically, as I don't know how many files I need.
Each TableRow has an ID starting by 100 and continue 200, 300 and so on.
When I create the row 3 the TableRow's ID is 300.
Then when someone edit other row I need to know what row is just to work with the elements of the row.
My problem: previous value:
trActiva.getId()=300
Then this is my code I put:
lineaActiva = (tv.getId()) / 100 * 100;
trActiva = findViewById(lineaActiva);
just on the point before these two lines trActiva.getId()=300
after the first row of the code lineaActiva = 200
That means after the second line trActiva.getId() should be 200 but it is still 300.
More weird things:
after these two lines:
trActiva.getId()=300
findViewById(lineaActiva).getId()=200
What is happening here? Why trActiva is not changing?
Thank you!!
We are unsure how you are increasing your Id and how you are storing your data as well how do you view 300 rows on a computer screen
So a lot of code is missing to give a very pointed answer to your question
Here is a table we populate from a Derby Database
The table is named ptable and we might also mention we are using a Model View Controller pattern to manage the data to GET and SET variables
First we read from the Database and populate the ptable with this code
private void ReadFromParent() throws SQLException{
ObservableList<ParentModel> TableData = FXCollections.observableArrayList();
stmnt = conn.createStatement();
ResultSet rs = stmnt.executeQuery("SELECT * FROM Parent");
while (rs.next()){// Add data to observableArrayList TableData to select a table ROW
TableData.add(new ParentModel(rs.getString("PID"),rs.getString("pMonth"),rs.getString("pYear")));
}
PropertyValueFactory<ParentModel, String> IDCellValueFactory = new PropertyValueFactory<>("PID");
colID.setCellValueFactory(IDCellValueFactory);
PropertyValueFactory<ParentModel, String> DateCellValueFactory = new PropertyValueFactory<>("pMonth");
colMonth.setCellValueFactory(DateCellValueFactory);
PropertyValueFactory<ParentModel, String> TypeCellValueFactory = new PropertyValueFactory<>("pYear");
colYear.setCellValueFactory(TypeCellValueFactory);
// ================================================================
// colTxDate are the ID's for the tableview columns
// sortDate are the Column Names for the Database TABLE CDBalance
// ================================================================
colMonth.setStyle("-fx-alignment: CENTER;");
colYear.setStyle("-fx-alignment:CENTER;");
Collections.sort(TableData, (p2, p1)-> p1.getPID().compareToIgnoreCase(p2.getPID()));
// Line of Code above Sorts Database Columns based on VARIABLE in ParentModel
// Change p2,p1 to sort Ascending or Descending
if(TableData.size() < 15) {// Format TableView to display Vertical ScrollBar
ptable.setPrefWidth(336);// 19 is the off set
}else {
ptable.setPrefWidth(355);
} ptable.setItems(TableData);
stmnt.close();
}
Then we write listener code to permit us to view the details of the row selected
Notice we get the ID from the row selected
This is where you can use that value to find the new entry that is greater than 300
OR you can write a Search query on the table that finds all records that have an ID greater than 300
Here is the code that permits you to click on a row in the table
private void showTableDataDetails(ParentModel info) throws IOException{
if (info != null) {
info = (ParentModel) ptable.getSelectionModel().getSelectedItem();
strID = info.getPID();
strMONTH = info.getPMonth();
strYEAR = info.getPYear();
toChildView();
System.out.println("########### PID "+strID);
}
}
#Override
public void initialize(URL url, ResourceBundle rb) {
ptable.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends ParentModel>
observable,ParentModel oldValue, ParentModel newValue) -> {
try {
showTableDataDetails((ParentModel) newValue); // When a row of the table is Selected call
// Proper Construction // showTableDataDetails method
} catch (IOException ex) {
Logger.getLogger(ParentTableViewController.class.getName()).log(Level.SEVERE, null, ex);
}
});
}
Hope this helps and Welcome to Stack Overflow
PLEASE post a little more code in the future so your question can have a more definitive answer
like page number=1,page number=2 ans so on,is there any pre defined attribute for that in dynamic report API,I know the question is too dumb,but still i could not find an answer to this question even through google,pls help.
If you want to add page no to your report you need to add this line to your report object
try {
report()//create new report design
.columns(...) //adds columns
.pageFooter(cmp.pageXofY()) //shows number of page at page footer
.show() //shows report
.print() //prints report
...
} catch (DRException e) {
e.printStackTrace();
}
I want to Print JTABLE and A value from Text Field. Its like products detail and there Bill Print.
Here is the image.
Required Print is Table + Total Amount,
But so far i got JTable.print() only print table. is there any way to add other values at end as total ??
Here is the code of printing jtable.
MessageFormat header = new MessageFormat("Purchases Bill {0,number,integer}");
try {
table.print(JTable.PrintMode.FIT_WIDTH, header, null);
} catch (java.awt.print.PrinterException e) {
System.err.format("Cannot print %s%n", e.getMessage());
}
Use jtextfield1.print(); I think it will work. It will only print the specified textfield.
I am trying to learn Wicket. One of the problems I encounter, is changing the values of components like a label.
This is how I declare the label:
Label message = new Label("message", new Model<String>(""));
message .setOutputMarkupId(true);
add(message );
The only solution I can find:
Label newMessage= new Label(message.getId(), "MESSAGE");
newMessage.setOutputMarkupId(true);
message.replaceWith(newMessage);
target.add(newMessage);
Is there a better/easier way to edit the value of a Wicket label and display this new value to the user?
Thanks!
I think you did not understand what Models are. Your example could be rewritten as follows
Model<String> strMdl = Model.of("My old message");
Label msg = new Label("label", strMdl);
msg.setOutputMarkupId(true);
add(msg);
In your ajax event
strMdl.setObject("My new message");
target.add(msg);
I've created a jasper report with iReport and I can print it perfectly.
I need to print 3 examples of it (original example, client example, department example) with very few changes, for example changing a label in the report.
I pass PRINT_FOR as parameter to iReport.
Does any body know how to approach this goal?
HashMap parameters = new HashMap();
String option = "C:\\option.jasper";
JRDataSource beanDataSource = reportMapper.getDataSource();
JasperPrint jasperPrint = JasperFillManager.fillReport(option, parameters, beanDataSource);
JasperPrintManager.printPage(jasperPrint, 0, true))
A first thought is just make a general report template and have some "hooks" in which you can insert the differences for each version; you can send the "differences" via the parameters from Java.
Instead of using a Static Text field you can use a Text Field that allows you to use and expression to determine the text output. In this case you would check to see if the PRINT_FOR parameter is equal to the client or department and if not use the original value. You expression would look something like this:
($P{PRINT_FOR}.equals("DEPARTMENT") ? "Department Label" : ($P{PRINT_FOR}.equals("CLIENT") ? "Client Label" : "Original Label"))
Where Department Label is outputted when PRINT_FOR is equal to DEPARMTNENT, Client Label is outputted when PRINT_FOR is equal to Client, and Original Label is outputted if it is not equal to either of the above.
Also worth noting is that in the code snippet about you never set the value for the PRINT_FOR parameter in your java code and you are not using a generic HashMap. It should look something closer to:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("PRINT_FOR", "CLIENT");
UPDATE: Based on your comment, you basically want to do export all 3 reports as one at the same time. This can be accomplised by using the JRPrintServiceExporter. Basically create the three JasperPrint Objects, and put them in a list. Then use the exporter to print them out. Something like:
//add all three JasperPrints to the list below
List<JasperPrint> jasperPrints = new ArrayList<JasperPrint>();
...
//create an exporter
JRExporter exporter = new JRPrintServiceExporter();
//add the JasperPrints to the exporter via the JASPER_PRINT_LIST param
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
//this one makes it so that the settings choosen in the first dialog will be applied to the
//other documents in the list also
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG_ONLY_ONCE, Boolean.TRUE);
exporter.exportReport();
When you use your own JRBeanCollectionDataSource, you must create for each JasperPrint their respective JRBeanCollectionDataSource
JRBeanCollectionDataSource dsCliente = new JRBeanCollectionDataSource(listaDetalle);
JasperPrint jasperPrintCliente = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCliente, dsCliente);
listaJasperPrint.add(jasperPrintCliente);
JRBeanCollectionDataSource dsCaja1 = new JRBeanCollectionDataSource(listaDetalle);
JasperPrint jasperPrintCaja1 = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCaja, dsCaja1);
listaJasperPrint.add(jasperPrintCaja1);