marko stone

Greenhorn
+ Follow
since Oct 16, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by marko stone

i used this code for printing JPanel contents
all labels and tables in it printing WHITE COLOR. WHY ???
thanks

class JPanelMy extends JPanel implements Printable
{
JPanelMy(MainWindow src)
{
super();
this.src=src;
DateWork dw=new DateWork();
daydate=new JLabel(dw.getDayDate());
titlename=new JLabel();
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
setBackground(Color.white);
}
...
public void printData()
{
PrinterJob pj=PrinterJob.getPrinterJob();
pj.setPrintable(this);
pj.printDialog();
try
{
pj.print();
}
catch (PrinterException pe)
{
System.out.println("Printer Exception");
}
}
...
public int print(Graphics g,PageFormat pageFormat,int pageIndex) throws PrinterException
{
Graphics2D g2=(Graphics2D)g;
g2.setColor(Color.black);

int fontHeight=g2.getFontMetrics().getHeight();
System.out.println("fontHeight="+fontHeight);
().getDescent();
//System.out.println("fontDescent="+fontDescent);
pageFormat.setOrientation(PageFormat.LANDSCAPE);
double pageHeight=pageFormat.getImageableHeight()-fontHeight;
System.out.println("pageHeight="+pageHeight);
double pageWidth=pageFormat.getImageableWidth();
System.out.println("pageWidth="+pageWidth);
Dimension d0;
d0=getSize();
double panelWidth=(double)d0.width;
System.out.println("panelWidth="+panelWidth);
double panelHeight=(double)d0.height;
System.out.println("panelHeight="+panelHeight);
double scale=1;
System.out.println("scale="+scale);
if (panelWidth>=pageWidth)
{
scale=pageWidth/panelWidth;
System.out.println("scale="+scale);
}
double panelWidthOnPage=panelWidth*scale;
System.out.println("panelWidthOnPage="+panelWidthOnPage);
double oneRowHeight=fontHeight;
System.out.println("oneRowHeight="+oneRowHeight);
int numRowsOnAPage=(int)(pageHeight/oneRowHeight);
System.out.println("numRowsOnAPage="+numRowsOnAPage);
double pageHeightForPanel=oneRowHeight*numRowsOnAPage;
System.out.println("pageHeightForPanel="+pageHeightForPanel);
int totalNumPages=(int)Math.ceil((double)panelHeight/pageHeight);
System.out.println("totalNumPages="+totalNumPages);
totalNumPages=1;
if (pageIndex>=totalNumPages)
{
return (NO_SUCH_PAGE);
}
g2.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
g2.translate(0f,-pageIndex*pageHeightForPanel);

g2.setClip(0,(int)pageHeightForPanel*pageIndex,(int)Math.ceil(panelWidthOnPage),(int)Math.ceil(pageHeightForPanel));

g2.scale(scale,scale);
paint(g2);
g2.scale(1/scale,1/scale);
g2.translate(0f,pageIndex*pageHeightForPanel);
return (PAGE_EXISTS);
}
21 years ago
how resize width of column at jtable to width of jheader of this column ?
21 years ago
hi
i did this not long ago
i put all my jtables to jpanel and put it on jscrollpane
but i place jtables vertically
21 years ago
hello
i want remove all components from JPanel jp for add them there again with another values
for remove i use
jp.removeAll();
jp.repaint();
it's not work
jp.revalidate() have same effect
what's wrong ?
thanks
21 years ago
hi
trying to do array of jtables and put them on JPanel
why my jtable showing at part of screen center ? and why it's not resizing to full horizotal size of screen ? label l2 cover column headers at table
thanks
My declarations
TableC tablec[];
JScrollPane jsp;
JLabel label;
JPanel jp;
GridBagLayout gbl;
GridBagConstraints gbc;
in constructor i have

jsp=new JScrollPane(jp);
tablec=new TableC[100];
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.fill=GridBagConstraints.BOTH;
getContentPane().add(jsp);
setMainInfo(1);
public void setMainInfo(int num)
{
int i;
JLabel l2,l3;
l2=new JLabel("l2");
l3=new JLabel("l3");
for (i=0;i<num;i++)
{
gbc.gridwidth=GridBagConstraints.REMAINDER;gbl.setConstraints(l2,gbc);
jp.add(l2,gbc);
tablec[i]=new TableC(this);
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(tablec[i],gbc);
jp.add(tablec[i],gbc);
gbc.gridwidth=GridBagConstraints.REMAINDER;gbl.setConstraints(l3,gbc);
jp.add(l3,gbc);
}
repaint();
21 years ago
hello
i have JLabel and JTable
JLabel showing ok and JTable ok too except columnnames it's not showing
why ?
table_elements=new TableElements[1];
table_elements[0]=new TableElements(this);
Box bv=new Box(BoxLayout.Y_AXIS);
label=new JLabel("0");
bv.add(label);
bv.add(Box.createVerticalStrut(10));
bv.add(table_elements[0]);
jsp=new JScrollPane(bv);
getContentPane().add(jsp);
21 years ago
hi
i have five jTables and i want put them at one JScrollPane
how ?
thanks at advance
21 years ago
hello
i write some text in my jtextpane by insertString method. trying to do columns and don't know how align text
i use "\t" for tab and getting String length
but it's not worked at all
thanks
21 years ago
hello
i'm new in XML
what's SAX and JAXP ? any different at them ?
or they used for same things ?
hello
i have problem with printer
for example i have only 2 pages of text but printer says much more paper
i think i need use Pageable interface but
i'm try but not effect
here is my code without Pageble
anybody help me to set real number of pages ?
thanks at advance

import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
public class PrintUtilities implements Printable
{
private Component componentToBePrinted;
int iddoc;

PageFormat dpageFormat=new PageFormat();
Graphics2D g2;
Graphics g;
int fontHeight,fontDescent;
double pageHeight,pageWidth,compWidth,compHeight;
double scale=1;
double compWidthOnPage,oneStringHeight;
int numRowsOnAPage;
double pageHeightForC;
int totalNumPages;

public static void printComponent(Component c,int iddoc)
{
new PrintUtilities(c,iddoc).print();
}
public PrintUtilities(Component componentToBePrinted,int iddoc)
{
this.componentToBePrinted=componentToBePrinted;
this.iddoc=iddoc;

}

public void print()
{
PrinterJob printJob=PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
{
try
{
printJob.print();
}
catch(PrinterException pe)
{
System.out.println("Error"+pe);
}
}
}

public int print(Graphics g,PageFormat pageFormat,int pageIndex)
{
g2=(Graphics2D)g;
fontHeight=g2.getFontMetrics().getHeight();
fontDescent=g2.getFontMetrics().getDescent();
if (iddoc==2)
{
pageFormat.setOrientation(PageFormat.LANDSCAPE);
}
pageHeight=pageFormat.getImageableHeight()-fontHeight;
pageWidth=pageFormat.getImageableWidth();
compWidth=(double)componentToBePrinted.getSize().width;
compHeight=(double)componentToBePrinted.getSize().height;
scale=1;
if (iddoc==2)
{
if (compWidth>=pageWidth)
{
scale=pageWidth/compWidth;
}
}
compWidthOnPage=compWidth*scale;
oneStringHeight=fontHeight*scale;
numRowsOnAPage=(int)((pageHeight-fontHeight)/oneStringHeight);
pageHeightForC=oneStringHeight*numRowsOnAPage;
totalNumPages=(int)Math.ceil((double)compHeight/numRowsOnAPage);
if (pageIndex>=totalNumPages)
{
return (NO_SUCH_PAGE);
}
else
{
g2.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
g2.drawString("TЄЁрэшЎр "+(1+pageIndex),(int)pageWidth/2-35,(int)(pageHeight+fontHeight-fontDescent));
g2.translate(0f,-pageIndex*pageHeightForC);
g2.setClip(0,(int)(pageHeightForC*pageIndex),(int)Math.ceil(compWidthOnPage),(int)Math.ceil(pageHeightForC));
g2.scale(scale,scale);
componentToBePrinted.paint(g2);
g2.scale(1/scale,1/scale);
g2.translate(0f,pageIndex*pageHeightForC);
return (PAGE_EXISTS);
}
}
}
21 years ago
Hello
i created 3 documents in my API and now i need printed them
one of them have large strings of data so can i rotate printing ???
and second when printer working it shows for example "Pages 3 of 75"
but i have my doc more less then 75 ? what's wrong ? where it takes these 75 ???
thanks
my code is below
import java.awt.*;
import javax.swing.*;
import java.awt.print.*;
public class PrintUtilities implements Printable
{
private Component componentToBePrinted;
int iddoc;

public static void printComponent(Component c,int iddoc)
{
new PrintUtilities(c,iddoc).print();
}
public PrintUtilities(Component componentToBePrinted,int iddoc)
{
this.componentToBePrinted=componentToBePrinted;
this.iddoc=iddoc;

}

public void print()
{
PrinterJob printJob=PrinterJob.getPrinterJob();
printJob.setPrintable(this);
if (printJob.printDialog())
{
try
{
printJob.print();
}
catch(PrinterException pe)
{
System.out.println("Error"+pe);
}
}
}
public int print(Graphics g,PageFormat pageFormat,int pageIndex)
{
Graphics2D g2=(Graphics2D)g;
int fontHeight=g2.getFontMetrics().getHeight();
int fontDescent=g2.getFontMetrics().getDescent();
double pageHeight=pageFormat.getImageableHeight()-fontHeight;
double pageWidth=pageFormat.getImageableWidth();
double compWidth=(double)componentToBePrinted.getSize().width;
double compHeight=(double)componentToBePrinted.getSize().height;
double scale=1;
if (iddoc==2)
{
if (compWidth>=pageWidth)
{
scale=pageWidth/compWidth;
}
}
double compWidthOnPage=compWidth*scale;
double oneStringHeight=fontHeight*scale;
int numRowsOnAPage=(int)((pageHeight-fontHeight)/oneStringHeight);
double pageHeightForC=oneStringHeight*numRowsOnAPage;
int totalNumPages=(int)Math.ceil((double)compHeight/numRowsOnAPage);
if (pageIndex>=totalNumPages)
{
return (NO_SUCH_PAGE);
}
else
{
g2.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
g2.drawString("Page "+(1+pageIndex),(int)pageWidth/2-35,(int)(pageHeight+fontHeight-fontDescent));
g2.translate(0f,-pageIndex*pageHeightForC);
g2.setClip(0,(int)(pageHeightForC*pageIndex),(int)Math.ceil(compWidthOnPage),(int)Math.ceil(pageHeightForC));
g2.scale(scale,scale);
componentToBePrinted.paint(g2);
g2.scale(1/scale,1/scale);
g2.translate(0f,pageIndex*pageHeightForC);
return (PAGE_EXISTS);
}
}
}
22 years ago
hi
how i can send jtextpane to printer ???
thanks
22 years ago
i used URLConnection
22 years ago
2 questions
1.i want refresh my jsp page when servlet will full loaded
how i can track it ?
2. this jsp get some parameter from servlet
in servlet i use
RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/MyJSP.jsp?param1="+value);
dispatcher.forward(req,res);
how i can get it in JSP ?
thanks
22 years ago
well
i got another way
i use sendRedirect method
and have another problem now
i don't know how i can send parameters
(without session) from one servlet to another
trying use RequestDispatcher but not work
any solves ?
22 years ago