Simple text printing with pagebreaks

I have a report displayed in a GUI application as a simple text within JTextComponent.
My goal is to print it but with page breaks at certain points.
I have inserted \f at those places, however when I print page breaks are ignored and I get a weird character printed in those places where \f was and the rest of the text is just printed out without page breaks.

One thing I v noticed is that if I output the report to a file and open it with MS Word page breaks are recognised and report is displayed correctly. However, if I try to open it with notepad page breaks are not recognised.
I have tried converting the text to RTF but the \f character was still ignored.

I would really appreciate if anyone shares their experience with something similar and how did you solve it


Posted On: Wednesday 17th of October 2012 05:58:59 AM Total Views:  642
View Complete with Replies

Related Messages:

Swing simple   (243 Views)
import javax.swing.*; public class Main { public static void main(String[] args) { // TODO code application logic here JFrame frame = new JFrame () ; JButton button = new JButton ("click me"); JLabel lab1 = new JLabel("I am a Label"); // JTextField text1 = new JTextField(10); frame.getContentPane().add(button); frame.getContentPane().add(lab1); // frame.getContentPane().add(text1); frame.setSize(300,300); frame.setVisible(true); } }, abalfazl hossein wrote:JButton.setPreferredSize(new Dimension(83, 291));
simple program but not able to get the required output   (303 Views)
i wrote a simple code that changes the color of the frame when the button is clicked ,the thing is when i run the program i am getting the output of the previous program (a frame that just displays a button) which i wrote .I am using eclipse indigo .Eclipse says there is an error in the project but where the error is it is not showing. import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class redorgreen { public static void main(String []args) { test t =new test(); } } class test extends JFrame implements ActionListener { test() { setSize(500, 500); setVisible(true); setLayout(new FlowLayout()); JButton red=new JButton(); JButton green =new JButton(); red.setActionCommand("red"); green.setActionCommand("green"); red.addActionListener(this); green.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent evt) { if(evt.getActionCommand().equals("red")) { getContentPane().setBackground(; repaint(); } else getContentPane().setBackground(; repaint(); } }
Doubt about layouts.. (its simple I think)   (240 Views)
My doubt is simple, I dont want to use AbsoluteLayout. So, I putted a Panel inside a frame on the West position using BordeLayout (default). Then I set the frame layout to BoxLayout (YAXIS). So I putted a JLabel and a JTextBox. I wanted it: Nome: [___________________________________] But the JTextBox extended until the border of the panel. How do I fix it
How can I show new text in JTextArea while program is executing?   (239 Views)
Hi all, first post here, and I most definitely am a greenhorn. I have a program that reads in data from files, and then it analyzes that data, and then spits out an analysis of the data into an html page. This all works just fine. However, sometimes it takes the program a while to analyze the data file, as some of the data files that users read can be rather large. . And, if the data file IS a large file, I want status updates to be sent to the user, so they know the program is not hung. So, the GUI of my program is a JPanel with a TextPanel that has a JTextArea, and that works fine too. That is, for the most part. Because, anytime I 'add' or 'append' text to the area it does work. However, and this is my problem, if the data file IS a large file, my status messages added to the JTextArea do not show up until AFTER the entire file has been analyzed, and by that point they are obviously useless. TextPanel = new JPanel(); TextPanel.setLayout(new BorderLayout()); Text = new JTextArea("blah, blah",x,y); Now, my program has a function where it determines the size of the file that the user specified for it to read. If the file is over a certain size, then it reads in chunks of the file at a time and then does analysis on each chunk, and after all chunks have been analyzed, it puts the file back together and all that works just fine, except for status updates. It is in the part of the code that I want the status updates . . . int numOFbuffers = filesize/buffersize; if (numOFbuffers > 0) { moreData = true; while (numOFbuffers >= 0) { Text.append("\nWorking...\n");
in a JTable, changing column header text alignment for specific columns only   (266 Views)
, At what classes should one look at (research) when trying to change the alignment of the header text for a specific column in a JTable I figured out how to change the entire JTableHeader text aligment through the getDefaultRenderer(), but I cannot figure out how to make certain column headers to be aligned left, while others are right.
First and Last Row numbers from viewable portion of jtextarea?   (224 Views)
HI, I am trying to get the row numbers of first and last from viewable portion of jtextarea. The starting row is working correctly, but i am not getting the last row number.
change text area background color at run time.   (227 Views)
I have text area which is initially disabled on a button click i am enabling it and I am trying to change background color at run time but its not working. Can any body help me I am doing the below: notesJTextArea.setEditable(editable); Color color = Color.white; notesJTextArea.setBackground(color);
change the texts to a different one in a JButton each time it is pressed.   (220 Views)
hello friends i am new to gui programming.. i was testing the following simple code public class SimpleGui implements ActionListener { JButton button; public static void main(String[] args) { SimpleGui gui=new SimpleGui(); gui.go(); } public void go() { JFrame frame=new JFrame(); button=new JButton("click me"); button.addActionListener(this); frame.add(button); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300,300); frame.setVisible(true); } @Override public void actionPerformed(ActionEvent event){ button.setText("button clicked"); } }
disable selection on double click in textpane   (206 Views)
For my application i want to disable the textpane from selecting a word when double click is performed on the word. Is there a way to do this
Positioning slider relative to word in JtextPane.   (182 Views)
I am hoping to get some advice on a problem I am trying to tackle. In my application, I have a single line textpane inside a scrollpane. The user will input some text (that could be longer than the length of the textpane - hence the scrollpane!). What I eventually want to achieve is that if the user clicks on any of the words in the text, I would like to have a slider popup right next to the word. So essentially, I need to find the exact position of the word and put the slider there. Please give me some tips to achieve this.
Setting the cursor in a text field after clicking a button?   (195 Views)
I have a JButton programmed in a SWing GUI that when I click it, it will take the score and put it into a JLabel somewhere else. The thing is when I click the JButton the cursor doesn't reset back to the JTextField. How would I go about doing that
displaying the file name of a pendrive in a text area by clicking a button   (230 Views)
hi .... my project is on pen drive where deer l b a display screen and with blue tooth functionality... i have a code which is displaying the list name but not in the text area... please help me out in this .... import; import java.awt.*; import java.awt.event.*; public class DirectoryReader { static int spc_count=-1; static void Process(File aFile) { spc_count++; String spcs = ""; for (int i = 0; i < spc_count; i++) spcs += " "; if(aFile.isFile()) System.out.println(spcs + "[FILE] " + aFile.getName()); else if (aFile.isDirectory()) { System.out.println(spcs + "[DIR] " + aFile.getName()); File[] listOfFiles = aFile.listFiles(); if(listOfFiles!=null) { for (int i = 0; i < listOfFiles.length; i++) Process(listOfFiles[i]); } else { System.out.println(spcs + " [ACCESS DENIED]"); } } spc_count--; } public static void main(String[] args) { String nam = "H:/"; File aFile = new File(nam); // textArea.add(Process(aFile)); Button b; Frame frame=new Frame("Text Frame"); TextArea textArea=new TextArea("hello!Welcome to BLUE PEN world",4,30); frame.add(textArea); frame.setLayout(new FlowLayout()); frame.setSize(250,250); frame.setVisible(true); textArea.setEditable(true); frame.add(b = new Button(""),BorderLayout.CENTER); frame.add(b = new Button("ok"),BorderLayout.NORTH); frame.add(b = new Button("v"),BorderLayout.EAST); frame.add(b = new Button("^"),BorderLayout.WEST); frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } }
Is there a standard way of creating a text field that requires the input to be an integer?   (208 Views)
I've been googling this and as is typical of Java, have found at least ten suggestions, all different and spanning about 8 years. I have a GUI with a text field a want the field to be limited to integer values. The simplest approach seemed to be: import java.util.*; import java.text.*; import java.awt.*; import javax.swing.*; import java.text.NumberFormat; class IntegerField extends JFrame { IntegerField() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel =new JPanel(); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(0); JFormattedTextField lhField = new JFormattedTextField(nf); NumberFormat ni = NumberFormat.getIntegerInstance(); JFormattedTextField rhField = new JFormattedTextField(ni); lhField.setColumns(4); lhField.setHorizontalAlignment(JTextField.RIGHT); rhField.setColumns(4); rhField.setHorizontalAlignment(JTextField.RIGHT); panel.add(lhField); panel.add(rhField); getContentPane().add(BorderLayout.SOUTH, panel); setSize(200,100); setVisible(true); } public static void main(String[] args) { IntegerField ifield = new IntegerField(); } }
validation for setting the text value in next text box based on selection of choices in current cho   (211 Views)
In my screen i had one button while clicking te button , it add textbox,combobox,label dynamically I need a validation for setting the text value in next text box based on selection of choices in current choosen combobox. I had written the code as below for if (e.getSource().equals((JComboBox)e.getSource())) { Object source = e.getSource(); JComboBox FieldTypePicks =(JComboBox)source; KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); //Sizevalue=e.getSource(); KeyNamePair pp = (KeyNamePair) FieldTypePicks.getSelectedItem(); int choice = 0; if (pp != null) choice = pp.getKey(); if (choice == 1){ JTextField Sizevalue = new JTextField(); this.requestFocus(); manager.focusNextComponent(Sizevalue); //Sizevalue.setText()= if (Sizevalue instanceof JTextField) { //Help here to set the text value in textbox near to Combobox System.out.println("Choice1"+Sizevalue.getText()); Sizevalue.setText("GG"); } //SizeLabelText1.setText("10"); } please help me to set the value in Textbox
I need to have my program take information from text file Plus my pie chart is in wrong place   (220 Views)
This is my last class and I am confused i really need a good grade to pass the class I need it to reaad a file then show a pie chart heres the first part of the code i will also include my piechart code and text file thanks for your help its due tonight /*/** Mortgage Calculator Program * Week 5 PRG421 *Change Request #7 High-Level Requirements Requestor: Ninfa Pendleton - Rapid City, SD Write the program in Java (with a graphical user interface) * and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage and the user's selection from a menu of available mortgage loans: * 5 years at 5% * 7 years at 5.35% 15 years at 5.5 % 30 years at 5.75% * * 35 years at 5.85% Use an array for the mortgage data for the different loans. Read the year and interest rates to fill the array from a sequential file. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Add graphics in the form of a chart (functioning pie chart or bar graph, that shows loan principal, total interest, and total amount paid over loan). ow the user to loop back and enter a new amount and make a new selection or quit. Please insert comments in the program to document the program. * To change this template, choose Tools | Templates * and open the template in the editor. * Laurie Watson * June 27,2011 */ import java.awt.*; import javax.swing.*; import java.awt.event.*; import*; import java.text.*; import java.util.*; //declare calculator class public class Calculator extends JFrame { // Holds years, interest rate strings read from file ArrayList standardTerms = new ArrayList(); String[] rates; String[] years; private JLabel amountLabel = new JLabel("Mortgage Amount:"); private JTextField amount = new JTextField(); private JLabel termLabel = new JLabel("Term of Loan:"); private JTextField term = new JTextField(); private JLabel rateLabel = new JLabel("Rate: ('0.0525')"); private JTextField rate = new JTextField(); private JComboBox termList = new JComboBox(); private JLabel payLabel = new JLabel("Monthly Payment:"); private JLabel payment = new JLabel(); private JButton calculate = new JButton("Calculate"); private JButton clear = new JButton("Clear"); private JButton exit = new JButton("Exit"); private JTextArea paymentSchedule = new JTextArea(); private JScrollPane schedulePane = new JScrollPane(paymentSchedule); private JLabel displayChart = new JLabel("Mortgage Graph"); private Container cp = getContentPane(); public Calculator(String title) { super.setTitle(title); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getStandardLoanTermsFromFile(); termList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); int cbIndex = cb.getSelectedIndex(); if (cbIndex > -1) { String[] parts = standardTerms.get(cbIndex).split(","); term.setText(years[cbIndex]); rate.setText(rates[cbIndex]); } } }); //handle the button events calculate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { //calculate the payments. double p = Double.parseDouble(amount.getText()); double r = Double.parseDouble(rate.getText()) / 12; double n = Integer.parseInt(term.getText()) * 12; double monthlyPayment = p * Math.pow(1 + r, n) * r / (Math.pow(1 + r, n) - 1); DecimalFormat df = new DecimalFormat("$###,###.00"); payment.setText(df.format(monthlyPayment)); //calculate the loan information double principal = p; int month; StringBuffer buffer = new StringBuffer(); buffer.append("Month\tAmount\tInterest\tBalance\n"); for (int i = 0; i < n; i++) { month = i + 1; double interest = principal * r; double balance = principal + interest - monthlyPayment; buffer.append(month + "\t"); buffer.append(new String(df.format(principal)) + "\t"); buffer.append(new String(df.format(interest)) + "\t"); buffer.append(new String(df.format(balance)) + "\n"); principal = balance; } paymentSchedule.setText(buffer.toString()); DisplayChart component = new DisplayChart(p, r); add(component); } catch (Exception ex) { System.out.println(ex); } } }); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { term.setText(""); rate.setText(""); amount.setText(""); payment.setText(""); paymentSchedule.setText(""); } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(1); } }); JPanel calcScreen = new JPanel(); calcScreen.setLayout(new GridLayout(10, 4)); calcScreen.add(amountLabel); calcScreen.add(amount); calcScreen.add(new Label("Select Mortgage Terms from List or enter manually")); calcScreen.add(termList); calcScreen.add(termLabel); calcScreen.add(term); calcScreen.add(rateLabel); calcScreen.add(rate); calcScreen.add(payLabel); calcScreen.add(payment); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.add(calculate); buttons.add(clear); buttons.add(exit); JPanel component = new JPanel(); add(component); JPanel calc = new JPanel(); calc.setLayout(new BoxLayout(calc, BoxLayout.Y_AXIS)); calc.add(calcScreen); calc.add(buttons); cp.add(BorderLayout.NORTH, calc); cp.add(BorderLayout.CENTER, schedulePane); } private void getStandardLoanTermsFromFile() { try { String line; BufferedReader br = new BufferedReader(new FileReader("term.txt")); while ((line = br.readLine()) != null) { standardTerms.add(line); termList.addItem(line); } br.close(); int numberOfLoans = standardTerms.size(); //allocate the arrays rates = new String[numberOfLoans]; years = new String[numberOfLoans]; String [] temp; for (int index = 0; index < numberOfLoans; index ++) { temp = standardTerms.get(index).split(","); years[index] = temp[0]; rates[index] = temp[1]; } } catch (Exception ex) { System.out.println(ex.toString()); } } public static void main(String[] args) { Calculator frame = new Calculator("Mortgage Calculator"); frame.setSize(800, 900); frame.setVisible(true); } }
How to do slide-in menus and text over video overlays   (235 Views)
I have designed and coded J2EE for years and have even written a stand-alone ap using AWT and Swing. So I'm not new to Java. But now I have my first serious desktop ap to develop. It will be a stand-alone and will only run on a windows based machine. I need to use Java because I jumped straight from mainframe coding to Java and have almost no background in C/C++/C#. Yes, I could learn C++ but the opportunity would be gone before I could gain any proficiency. And I much prefer Java anyway. I plan to use SWT/JFace because native efficiency and performance is a top priority. I am just now starting to dig into the SWT and JFace APIs and tutorials. The ap will display on a small touch screen monitor of about 8" or 10" diag, (not any sort of notepad) so screen real estate is extremely important. One important thing is that I will have a video capture displaying and I need to overlay text and draw lines over the video. I think I am slowly putting together some hint of possibility on how to do this but I still have a long way to go. If anyone has some suggestions of reference material and tutorials to help me with this I would greatly appreciate it!!! There needs to be a fairly significant menu structure to the ap to control a lot of functionality. with a touch interface so larger size buttons would be best. I really don't want to load up the limited space with buttons. So what I have in mind is to have a single button in a corner or an arrowhead on an edge where someone would touch and the menu options slide in. Then once a function is selected the menu would slide back out of sight and the original arrow would come back. I would prefer that at least the arrow button be somewhat transparent. it would be even better if the menu that slides in would also be maybe 40%-50% transparent. Is this something that can be done in SWT/JFace Again could someone suggest some research material and/or tutorials I would need to figure this out I'm not looking for someone to give me all the code. Just some information as to where I can learn how to do it. I've been Googling for days now and haven't gotten anywhere. There are tons of reference material and tutorials that I will be studying but nothing that gives me any hope that I can make this happen. I'm convinced it can be done, if I have the right resources available. Is it possible I would have to go all the way down to where I am drawing the buttons manually and moving them into place with the code That's ok. I just hope I don't have to start totally from scratch. Any productive comments and suggestions would be greatly appreciated.
getting result in textfield using jlist   (231 Views)
hai i'm trying to use a jtextfiled with a i'm getting the values from a database to the jlist and whenever i type the name i want, i'm getting the result in the jlist...but i can't use the arrowkeys to select these values to jtextfield...i'm able to do it with mouse so i have to get the values in the jlist to the textfield using the arrowkeys..or enter key using the arrowkeys to traverse through the jlist i hope you can help me....if my query is not clear please reply...please do help.. nijin--
Hiding text in JTable   (247 Views)
I have a table listing some information including a color. The color is displayed by changing the background color of the table. The text describing the color is "hidden" by changing the text color to match the background. Is it possible to turn off the text display class ColorTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; Object rowData[][] = { { "1", Color.RED }, { "2", Color.BLUE }, { "3", Color.GREEN } }; String columnNames[] = { "English", "Color" }; public int getColumnCount() { return columnNames.length; } public String getColumnName(int column) { return columnNames[column]; } public int getRowCount() { return rowData.length; } public Object getValueAt(int row, int column) { return rowData[row][column]; } public Class getColumnClass(int column) { return (getValueAt(0, column).getClass()); } public void setValueAt(Object value, int row, int column) { rowData[row][column] = value; } public boolean isCellEditable(int row, int column) { return (column != 0); } } class ColorChooserEditor extends AbstractCellEditor implements TableCellEditor { private static final long serialVersionUID = 1L; private JButton delegate = new JButton(); Color savedColor; public ColorChooserEditor() { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color color = JColorChooser.showDialog(delegate, "Color Chooser", savedColor); ColorChooserEditor.this.changeColor(color); } }; delegate.addActionListener(actionListener); } public Object getCellEditorValue() { return savedColor; } private void changeColor(Color color) { if (color != null) { savedColor = color; delegate.setBackground(color); } } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { changeColor((Color) value); return delegate; } } public class ChooserTableSample { public static void main(String args[]) { JFrame frame = new JFrame("Editable Color Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TableModel model = new ColorTableModel(); JTable table = new JTable(model) { private static final long serialVersionUID = 1L; @Override public Component prepareRenderer( final TableCellRenderer renderer, final int Index_row, final int Index_col ) { final Component comp = super.prepareRenderer( renderer, Index_row, Index_col ); if ( Index_col == 1) { // Set background color Object v = this.getValueAt( Index_row, Index_col ); Color c = (Color) v; comp.setBackground( c ); comp.setForeground( c ); //
how to color a particular word in a jtextpane?   (165 Views)
i have searched in the google but all examples are quite complex so this is my code can you give a example code to color a particular text like "void" so that i can learned it in a simple way please package highlighter; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultHighlighter; /** * * @author Admin */ public class Highlighter implements KeyListener{ /** * @param args the command line arguments */ JTextPane text; void gui() { JFrame frame = new JFrame(); text = new JTextPane(); frame.add(text, BorderLayout.CENTER); String s = text.getText(); s.indexOf(s); int lenght = s.length(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } public static void main(String[] args) { // TODO code application logic here new Highlighter().gui(); } public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { throw new UnsupportedOperationException("Not supported yet."); } public void keyReleased(KeyEvent e) { throw new UnsupportedOperationException("Not supported yet."); } }
How do you make the textfield and button the same size? FlowLayout   (193 Views)
Guys, I'm using Flow Layout for my search panel for some reason.. The Jtextfield and button is of different height, I have try setting the size and etc. but it doesn't work.