How to insert html table inside java code
Hi,
I want to send an email with data in table format(with rows and columns) .Please tell me how to achieve this in java code .I just want to know the code for making the table in java
Please help me
Thanks in advance
NewUser7 wrote:
Please tell me how to generate html tables in java. .. Do you know how to produce an HTML table in HTML?
..i dont have jspI did not mention JSP. Pure J2SE code can produce HTML, though if done in a web-app., it would generally be done using JSP or Servlets.
Here is an example of producing HTML in J2SE.
import javax.swing.*;
class HtmlTable {
public static void main(String[] args) {
int[][] values = {
{1,3894,5387},
{2,4112,4459},
{3,4886,6076}
String prefix = "<html><body><table>\n";
final StringBuilder sb = new StringBuilder(prefix);
sb.append("<tr>");
sb.append("<th>");
sb.append("Month");
sb.append("</th>");
sb.append("<th>");
sb.append("Unit A<br>Sales");
sb.append("</th>");
sb.append("<th>");
sb.append("Unit B<br>Sales");
sb.append("</th>");
sb.append("</tr>\n");
for (int ii=0; ii<values.length; ii++) {
sb.append("<tr>");
for (int jj=0; jj<values[ii].length; jj++) {
sb.append("<td>");
sb.append("" + values[ii][jj]);
sb.append("</td>");
sb.append("</tr>\n");
sb.append("</table>");
sb.append("</body>");
sb.append("</html>");
Runnable r = new Runnable() {
public void run() {
JOptionPane.showMessageDialog(
null,
new JTextArea(sb.toString(),20,10) );
JOptionPane.showMessageDialog(
null,
new JLabel(sb.toString()) );
SwingUtilities.invokeLater(r);
As an aside, those terms are HTML (an abbreviation) Java (a proper name) & JSP (an abbreviation). Please try to use correct upper/lower case when using technical terms.
Similar Messages
-
How to trigger tree table from java code
Trying to trigger tree table from java code, using :
AdfFacesContext.getCurrentInstance().addPartialTarget(treeTableComponent);
But its not working. Am i using the correct approach?Sorry for the incomplete information,
I have a tree table in a region and that region i am including inside a jspx file. In the region i have one popup and based on the input taken from the popup i want to trigger the table to show the data.
For that i am trying :
FacesContext context = FacesContext.getCurrentInstance();
UIComponent component = findComponent( context.getViewRoot(),"treeTableID");
if(component != null){
AdfFacesContext.getCurrentInstance().addPartialTarget(component);
public static UIComponent findComponent(UIComponent base, String id)
if (id.equals(base.getId()))
return base;
UIComponent children = null;
UIComponent result = null;
Iterator childrens = base.getFacetsAndChildren();
while (childrens.hasNext() && (result == null))
children = (UIComponent) childrens.next();
if (id.equals(children.getId()))
result = children;
break;
result = findComponent(children, id);
if (result != null)
break;
return result;
Model is getting data before i use : AdfFacesContext.getCurrentInstance().addPartialTarget(component);
But table is not calling getData() in model to show the populated data on UI. -
How to insert html table tag in flash.
i am trying to insert my html table format into flash... but flash doesn't support that html table tags....
i'm creating a filp book for help manual.. In that we use flash and html tags... His there any other way to insert html table in to flash...
give ur suggestions..
thanks.As you say, Flash does not support html table tags. Create your own tables using textfields and if you need borders around cells use either textfield borders or lines surrounding the textfields.
-
How to use html tags inside java
I have to retrieve data from db and return the data to my index.jsp page.
Its working fine.
But I have o display in a pable format using html. How to embed html tags? I tried this way. Its not working. Any suggestions?
String htmlOpen = "<html>";
String htmlEnd = "</html>";
String titleOpen ="<title>";
String titleEnd ="</title>";
String bodyOpen = "<body>";
String bodyEnd = "</body>";
for (int i = 1; i <= cols;i++){
output = output + rsmd.getColumnName(i);
while (rst.next()) {
for (int i = 1; i <= cols;i++){
output = output +rst.getString(i);
result = htmlOpen + titleOpen + titleEnd + bodyOpen + output+ bodyEnd + htmlEnd;
stmt.close();
conn.close();
return htmlOpen;
}See those charcters in your JSP that look like "<%"? Those characters mean: "the code after this is Java - interpret it as such".
Then when you close your Java block with "%>", it then means: "the code after this is html - output it to the request response that is being built. However, within the html code, the syntax "<%= java_variable_name %>" means "take the current value of that Java variable and insert it into the html output".
Here's an example:
%>
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<%
String s = null;
for (int i = 1; i <= ncol; i++)
s = rsmd.getColumnName(i);
%>
<th nowrap><A HREF="<%=sortLink.toString()%>&sortby=<%=s%>"><%= s %></th>
<%
%>
</tr>
<%
if (rs == null || numRows <= 0)
%><tr><td colspan="10" nowrap>No data available for specified query.</td></td><%
else
int rowCounter = 0;
while(rs.next() && rowCounter < PAGE_SIZE)
rowCounter++;
%>
<tr><%
for (int i = 1; i <= ncol; i++)
s = rs.getString(i);
if (rsmd.getColumnName(i).equalsIgnoreCase("password"))
%><td nowrap>********</td>
<%
else
%><td nowrap><%= s %></td>
<%
%></tr><%
%>
</table>This is JSP 101, what they teach in the first hour of class...
Here's a decent JSP tutorial:
http://www.jsptut.com/ -
How to insert HTML content directly in code from JEditorPane ?
I'm developping an HTML Editor on a JEditor Pane.
The problem is that a blank is not interpreted, and i've tried to add "& n b s p ;" in the code from a KeyListener added to the VK_SPACE event, or to define an Action to add HTML Spaces. But i didn't achieve to...
I just want to insert a "& n b s p ;" in the HTML code of the document displayed in the JEditor evry time the SpaceBar is pressed.
I've tried InsertContentAction() :
Not a solution :It inserts " & n b s p ;" in the text (it appears litteraly).
I've tried InsertHTML. But it needs a tag parameter, and in my case, i need no tag
to be inserted.
I'm stuck since days... Any help woul be extremely appreciated...The code I now have is:
TextAction actInsertNBSP = new TextAction("insert-space"){
public void actionPerformed(ActionEvent evt){
//Where is the cursor now
int intInitialCaretPos = text.getCaretPosition();
try{
//Make HTML document to add the html code
HTMLDocument htmldoc = (HTMLDocument)text.getStyledDocument();
//Get document input attributes before insert
AttributeSet atr = kit.getInputAttributes().copyAttributes();
//Insert tag
kit.insertHTML(htmldoc,intInitialCaretPos,"<b>\240</b>", 0, 0, HTML.Tag.B);
//Set stored attributes to input attributes
kit.getInputAttributes().addAttributes(atr);
//Set cursor on right position
text.setCaretPosition(text.getCaretPosition());
}catch (Exception exc){
exc.printStackTrace();
KeyStroke kstSpace = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
text.getKeymap().addActionForKeyStroke(kstSpace,actInsertNBSP); -
How to insert a table in JTextPane("text/html")....
How to insert a table in JTextPane(with contentType(text/html))....like we insert bold/italics etc..AND when I retrieve the contents using getText(),I should be able to get the html tags for table.........!!!
Anyone Anywhere with solution..???-------
-
How to search inside java code?
How to search for pattern in Java code from NWDS? For example, I want to search for "wdThis" in java code. Where to look for find or search button?
Hi,
You can also use CTRL+H key for searching any Java or non-Java code across all projects you have opened in your workspace.
Just go to Project Explorer View and select any project, then press CTRL+H, a set of search option will show up.
Hope it helps.
Best regards,
David. -
Insert HTML table into JTextPane
hi people!
I'm inserting htmltable in JTtextPane.
The problem is, that borders aren't shown.
they are shown in browser, the code in source view is also valid, but in JTextPane they ar invisible. Can anyone tell me Why?
Here is a piece of code:
public class HtmlTable {
public static String insertTableString(int rows, int columns) {
String tableString="<TABLE Width=100% Border=1>";
for (int i=0; i<rows; i++) {
tableString+="<TR>";
for (int j=0; j<columns; j++)
tableString+="<TD> </TD>";
tableString+="</TR>";
tableString+="</TABLE>";
return tableString;
call of this method:
HTMLEditorKit kit;
HTMLDoc=(HTMLDocument)editorTextPane.getStyledDocument();
kit=(HTMLEditorKit)editorTextPane.getEditorKit();
kit.insertHTML(HTMLDoc,editorTextPane.getCaretPosition(),HtmlTable.insertTableString(HtmlTable.getRowNumber(), HtmlTable.getColumnNumber()),0,0,HTML.Tag.TABLE);no Java code involved, just HTML and CSS
<HTML>
<HEAD>
<style type="text/css">
td {border-top-width:1pt; border-style:solid; }
</style>
</HEAD>
<BODY>
<p>
Your Table goes here
</p>
<table>
<tr>
<td><p>Row 1 Col 1</p></td>
<td><p>Row 1 Col 2</p></td>
</tr>
<tr>
<td><p>Row 2 Col 1</p></td>
<td><p>Row 2 Col 2</p></td>
</tr>
</table>
</BODY>
</HTML> -
How to extract HTML table contents
Does someone know how to extract HTML table contents? I want to download a html file which contains table from internet and extract the table contents. Finally, insert the table contents into database.
To do this you have to user a Parser to parse your html file and retrieve the information you want.
Please have a look at the following classes:
HTMLEditorKit.ParserCallback
ParserDelegator()
Here is an example which retrives the FRAMSET src of an html file. The purpose here is to find if the html file describes a multi-frame page or not. If so it add the frame src name to a Vector
HTMLEditorKit.ParserCallback callback =
new HTMLEditorKit.ParserCallback() { public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)
if (t.equals(HTML.Tag.FRAME))
{ Logger.debug(this, "Frame tag found in "+f.getURL()); Enumeration e = a.getAttributeNames();
while (e.hasMoreElements())
Object name = e.nextElement();
if (name.toString().equals("src"))
Object ob = a.getAttribute(name);
Logger.debug("found an src "+ob);
currentFrameSrc.add(new String(ob.toString()));
Reader reader = new FileReader(aFile);
new ParserDelegator().parse(reader, callback, false);
It's not clean but I hope it will help :-)
Stephane -
How to insert a table with variable rows in smart form
Hi all,
How to insert a table with variable rows in smart form?
Any help would be appreciated.
Regards,
Mahesh.Hi,
Right click the mouse->create->table
If you want 5 columns, you need to declare 5 cells in one line type of the table
Click on Table -> Details, then do the following
Line Type 1 2 3 4 5
L1 2mm 3mm etc
Here specify the width of the columns as many as you want..
then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there. -
How to insert HTML content in a IVIEW
Hi,
How to insert HTML content in a iview any body help me with the solution.
Thanks & Regards
kiran.BHi,
You can just spit out HTML in the request object:
request.write("<B>Whatever</B>");
Or if you have a single HTML page, you might want to just add it to KM and create an iView from it.
Hope this helps.
Daniel -
How To Call HTML Page Through Java Swing Page ???....
Hi All ;
Please Can You Tell Me How To Call HTML Page Through Java Swing Page ....
Regards ;Hi,
you can use HTML fragments on a panel.
http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
However, to integrate a browser you need 3rd party software like IceBrowser
If you Google for: HTML Swing
then you find many more hints
Frank -
How to insert one table data into multiple tables by using procedure?
How to insert one table data into multiple tables by using procedure?
Below is the simple procedure. Try the below
CREATE OR REPLACE PROCEDURE test_proc
AS
BEGIN
INSERT ALL
INTO emp_test1
INTO emp_test2
SELECT * FROM emp;
END;
If you want more examples you can refer below link
multi-table inserts in oracle 9i
Message was edited by: 000000 -
How to Create adf table from java bean
Hi,
How to Create adf table from java class (Not from ADF BC).
Thanks
Satya@vlsn -- you have to follow what shay said.
Do the following in Model layer ::
create a table property java class with your columns setters and getters like :
*public class gridProps {*
private int sno;
private String orderNum;
*public void setSno(int sno) {*
this.sno = sno;
*public int getSno() {*
return sno;
*public void setOrderNum(String orderNum) {*
this.orderNum = orderNum;
*public String getOrderNum() {*
return orderNum;
Create another table java class which will populate the values to your column values and return the collection :
*public class gridPopulate {*
private List<gridProps> gridValues ;
*public List<gridProps> setToGrid(ArrayList<ArrayList> valuesToSet) {*
*if (valuesToSet == null) {*
return gridValues;
gridValues = new ArrayList<gridProps>();
if(btnValue.equals("completeBtn"))
return gridValues;
for(ArrayList<String> tempArr:valuesToSet)
gridProps gp = new gridProps();
gp.setSno(Integer.valueOf(tempArr.get(0)));
gp.setOrderNum(tempArr.get(1));
return gridValues;
Right click gridPopulate class and create this as data control.This class will be seen in Data control list.Under this data control,Drag the grid property collection(created earlier) to your page.Then execute your binding(gridPopulate) according to your logic.
Thanks.(My jdev version 11.1.1.5.0) -
How I post HTML and Video embed code from my component to landing page?
Hi there,
How I post HTML and Video embed code from my component to landing page?
My Components are developed in NODEJS and PHP.
ThanksAnswered here http://topliners.eloqua.com/thread/7944
Maybe you are looking for
-
I have two iTunes accounts. When I view account info on a older account that I seldom use, it indicated that it was associated with one device; I.e., my IPad. I am trying to link it to the other account instead
-
Unable to uninstall itunes 8.0.2.20
I am trying to upgrade to the latest version of itunes, but whenever i try, an error comes up. I have found that the same error occurs when i simply try to uninstall itunes from the control panel. Im wondering if this is an itunes problem that i can
-
I have a program that I have complied using LabWindows 2010. Program works fine under Windows XP, but under WIndows 7 the program gets a shield attached to the icon (see attachment). When running the program under Windows 7, it requests that an adm
-
I'm trying to create a foreing key constraint, between tables in diferents schemas. but i get ora-01031 insufficient privileges error, which is the system privilege that i need?
-
Lightroom 3.3 having problems keeping pan position when printing
Has anyone else run into the problem when printing from LR 3.3 that was fixed in LR 3.2. - namely Print: Image loses "pan" position when placed in cells that are not big enough When LR 3.0 was out they released 3.2 and fixed the above problem. Recen