|
<pre>
if(source.getSourceType() == Source.SERIALIZATION)
return deserializeEditor(source.getSerializedObject());
public JTextComponent deserializeEditor(InputStream inputStream)
{
JTextPane p;
System.out.println("deserialize existing document...");
p = new JTextPane();
p.setPreferredSize(new Dimension(labelDimension.getWidth(), labelDimension.getHeight()));
javax.swing.text.EditorKit kit = createEditorKit();
p.setEditorKit(kit);
ObjectInputStream ois = null;
try
{
ois = new ObjectInputStream(inputStream);
Object obj = null;
if((obj = ois.readObject()) != null && (obj instanceof Document))
{
Document doc = (Document)obj;
p.setDocument(doc);
System.out.println("set deserialized document");
}
}
catch(IOException e)
{
System.err.println(e.getMessage());
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
finally
{
safeClose(ois);
}
p.setDragEnabled(!hiddenMode);
return p;
}
public JTextComponent createEditorFromPage(Page page)
{
JTextPane p = new JTextPane();
Dimension dim = new Dimension(labelDimension.getWidth(), labelDimension.getHeight());
p.setPreferredSize(dim);
p.setMaximumSize(dim);
p.setSize(dim);
HTMLEditorKit kit = createEditorKit();
p.setEditorKit(kit);
p.setTransferHandler(new PlainTextTransferHandler());
if(page != null)
try
{
page.setPage(p);
}
catch(IOException e)
{
System.err.println("Attempted to read a bad URL: " + e.getMessage());
}
else
System.out.println("create empty label");
javax.swing.text.Style style = p.addStyle("24pts", null);
StyleConstants.setFontSize(style, 24);
style = p.addStyle("12pts", null);
StyleConstants.setFontSize(style, 12);
style = p.addStyle("Italics", null);
StyleConstants.setItalic(style, true);
style = p.addStyle("Bold", null);
StyleConstants.setBold(style, true);
p.addMouseListener(new PopupMenuMouseListener(new PopupMenuFactory((HTMLDocument)p.getDocument()), p));
p.setDragEnabled(!hiddenMode);
initializeDocument((HTMLDocument)p.getDocument(), p, kit);
return p;
}
</pre>
Save event is there if they click save event whole HTML image is going to save in BLOB object. In there I'm checking if its already save value or new value if its saved value it call deserializeEditor () in this method binary value is converting to string then it will show in editor if its new string value means just it will call createEditorFromPage() event which i showed in above code.
My problem is when they entering text in editor if its reach maximum characters or maximum lines it should open new page.
Its like "Wold document"
sorry while keypress the value I don't no which event is going to fire.please suggest which event is going to fire with any example.
naveenkrishna
|
|
|
|
|
I'm not able to get the printout.
Here is the code.
public class Billing extends Frame implements ActionListener,Printable
{
JButton printbtn = new JButton("Print");
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex > 0)
{
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)graphics;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
graphics.drawString("Hello world!", 100, 100);
return PAGE_EXISTS;
}
public Billing
(
printbtn.addActionListener(this);
JPanel panel = new JPanel();
panel.setLayout(new MigLayout("debug,fillx,filly", "[]rel:push[]", "[]1[]"));
panel.add(printbtn);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
)
@Override
public void actionPerformed(ActionEvent e)
{
else if (e.getSource().equals(printbtn))
{
System.out.println("You have clicked on Print Button!");
PrinterJob pj = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (pj.printDialog() == true)
{
try
{
pj.print();
}
catch (PrinterException exc)
{
System.out.println(exc);
}
}
System.out.println("Print Job Ends Here!!!!XXXXX!!!!");
}
}
|
|
|
|
|
Please get your code to a compilable form - everyone trying to read this has to guess what you actually mean several times to get that right.
Regards,
ab
|
|
|
|
|
Sorry my bad with Copy/Paste
Here is the code once again.
public class Billing extends Frame implements ActionListener,Printable
{
JButton printbtn = new JButton("Print");
JFrame frame = new JFrame();
PrinterJob job = PrinterJob.getPrinterJob();
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex > 0)
{
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)graphics;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
graphics.drawString("Hello world!", 100, 100);
return PAGE_EXISTS;
}
public Billing()
{
JPanel panel = new JPanel();
panel.setLayout(new MigLayout("debug,fillx,filly", "[]rel:push[]", "[]1[]"));
panel.add(printbtn);
frame.add(panel);
printbtn.addActionListener(this);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x=(int)((dimension.getWidth() - 760)/2);
int y=(int)((dimension.getHeight() - 550)/2);
frame.setLocation(x, y);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
public static void main(String[] args)
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
e.printStackTrace();
}
new Billing();
}
@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource().equals(printbtn))
{
System.out.println("You have clicked on Print Button!");
PrinterJob pj = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (pj.printDialog() == true)
{
try
{
pj.print();
}
catch (PrinterException exc)
{
exc.printStackTrace();
}
}
System.out.println("Print Job Ends Here!!!!XXXXX!!!!");
}
}
}
}
|
|
|
|
|
So two copies of your code but with no detail about your problem. Please explain exactly what you are trying to do, what results you expect, and what results you see, including the full text of any error messages.
Veni, vidi, abiit domum
|
|
|
|
|
I'm able to print Hello world with the help of my printer machine.
But with that code I don't get any error messages,but I'm able to print those two lines in the Console
1.You have clicked on Print Button!
2.Print Job Ends Here!!!!XXXXX!!!!
But not Hello world from this code
graphics.drawString("Hello world!", 100, 100);
What is wrong with this code?
|
|
|
|
|
|
I have got the solution
I have created two Printer Job
1.
PrinterJob job = PrinterJob.getPrinterJob();
2.
PrinterJob pj = PrinterJob.getPrinterJob();
And If I did this in my code
job.setPrintable(this);
I should not be doing this
if (pj.printDialog() == true)
pj.print();
Instead of "pj" I have to use "job".
that was the problem
I was not using the right job hehe.
|
|
|
|
|
how can i replace the two digits inside the number?
O/P:
536247982
After replacing
537246982
|
|
|
|
|
Write out, on paper, the two numbers and then the steps required to achieve the result. Then convert those steps in native language to Java code. It is really not that difficult. If you need some ideas then look at the Java Tutorial[^], particularly the section on numbers and strings.
Veni, vidi, abiit domum
|
|
|
|
|
How can i draw a curve in java? thank you.
|
|
|
|
|
|
Thanks alot.
|
|
|
|
|
Hi
I am facing this problem in my code and I'm unable to solve the problem. I can view data in utf-8 text file and there seems no problem. But what is in the RAF file, I cannot find. Thanks.
static void writeDataFile(String urText){
String strDataFilePath = "D:\\Documents\\JCreator Pro\\Font Images\\Images.dat";
String token[] = urText.split("\t");
RandomAccessFile file = null;
try {
file = new RandomAccessFile(strDataFilePath, "rw");
for (int i = 0; i < token.length; i++){
token[i] = token[i].replaceAll("\n", "");
file.writeInt(i);
int remain = i % 2;
if ( remain == 0){
file.writeUTF(token[i]);
}
else{
file.writeUTF(token[i]);
}
}
}
catch (IOException ex) {
System.out.println (ex);
}
finally{
try {
file.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
|
|
|
|
|
You need to look at the content of the data you are reading when the excption occurs, and the above code does not appear to be reading anything.
Veni, vidi, abiit domum
|
|
|
|
|
Thanks for reply. After sending the post I was able to settle the issue and that was just in the previous calling method.
|
|
|
|
|
I want a key Listener on a tabbed pane (Tab) so when I click on a tab I can do something.
I tried
public class Mainframe extends JFrame implements ActionListener,KeyListener
{
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addKeyListener(this);
tabbedPane.addTab("Tab 1 ",panel1);
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
tabbedPane.addTab("New Tab", panel2);
tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_1)
JOptionPane.showMessageDialog(null, "You have selected ","Tab Clicked",JOptionPane.PLAIN_MESSAGE);
}
@Override
public void keyReleased(KeyEvent e) {
}
}
It does nothing.
|
|
|
|
|
|
Change Listener works fine .
|
|
|
|
|
do that example application using struts 1.x
|
|
|
|
|
That's called cascading comboboxes. Your favorite search engine can help you with this search term.
|
|
|
|
|
|
// For establishing connection between JAVA and MS SQL Server, first you should have to add SQLJDBC.jar.
Click here for .jar file.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ConnectMSSQL {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection connection = DriverManager.getConnection(
"jdbc:sqlserver://<SERVERNAME>","<uid>", "<pass>");
System.out.println("DATABASE NAME IS:"
+ connection.getMetaData().getDatabaseProductName());
Statement statement = connection.createStatement();
ResultSet resultSet = statement
.executeQuery("select * from dbo.try");
while (resultSet.next()) {
System.out.println(resultSet.getString("Name"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
|
|
|
|
|
And what is your question?
Veni, vidi, abiit domum
|
|
|
|
|
excuse me sir, It's only article for information.
|
|
|
|