Facing problems printing a ScrolledComponent in SWT

Hi ,

I am facing problems printing a ScrolledComponent in SWT . I am able to print the contents that are visible but not able to print the contents below the scroll . This happens for both vertical and horizontal scroll . Can some one please suggest how to proceed .

Posted On: Monday 22nd of October 2012 01:01:53 AM Total Views:  465
View Complete with Replies

Related Messages:

JSlider update another JSlider problems   (274 Views)
Hi , I am taking Java classes at a college level. I am playing around with JSliders and an addChangeListener. The gist of my code is I have two sliders, one is MPH the other is KPH. When one slider is slid, the two fields update and the other slider follows. if you move the other slider, the same happes. My problems seems that when the addChangeListener updates the other slider, it calls the same addChangeListener and then they both stick at 0. I am using an if statement to run seperate commands depending on which slider calls the addChangeListener. in this code if I uncomment the statements to update the other slider in the addChangeListener then it doesnt work, with them commented, the other slider does not update. Im stuck.
having problems with setting the color of a buffered Imaghe   (389 Views)
I created a buffered image in my programme and I want it to have a green (orany color other than black)background however i have been unable to get it to change from black to any other other color.hers the code i have been working with .
Program.launch of Mac OSX TextEdit can cause problems   (279 Views)
My SWT application has been used in both Windows XP/Vista/7 and Mac OSX for several years. Recently, in certain org.eclipse.jface.action.Action classes I've added the option to open *.txt files (these are newly created operational reports). The files are opened by calling org.eclipse.swt.program.Program.launch(fileName), where fileName is the full path name for a particular *.txt file. In Windows, there are no issues with this scenario. In Mac OSX, if the user first launches the text-related program (e.g., TextEdit) before launching my SWT application, there are no issues with this scenario. In Mac OSX, if the user first exits the text-related program (e.g., TextEdit) launched by my SWT application before attempting to exit my SWT application (via menu's "Quit", etc.), there are no issues with this scenario. In Mac OSX, if the users does not exit the text-related program (e.g., TextEdit) launched by my SWT application before attempting to exit my SWT application, my SWT application's window closes... but the icon is left behind in the Dock (a.k.a., system taskbar) and my SWT application has not actually exited. I have to manually terminate my SWT application via Force Quit. Any suggestions about this problem would be welcome.
changing headers on JTable caused other problems   (246 Views)
Hi Guys, I'm working with a JTable which sets up certain columns with cell renderers and editors. My application allows the user to change the interface to a different language, so JMenuItems, buttons, etc. change their text and I've set it up so that the header on the JTable changes as well. Two lines of code make that happen: private void changeTableHeaders() { ((JLTableModel)table.getModel()).setHeaders(this.getHeaders()); ((JLTableModel)table.getModel()).fireTableStructureChanged(); }
Simple text printing with pagebreaks   (642 Views)
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 cheers
Scroll panel problems   (284 Views)
I am having alot of problems getting this scroll panel to work. Specifically I have the [panel on my GUI, but I cant figure out how to get the text area to populate it. Can someone please tell me what I a,m doing wrong here. These are the code portions that pertain to the scroll panel only. private JTextArea jtextarea1;//define textarea private JScrollPane scrollpane1;
printing a jtable   (601 Views)
I've got a swing JTable of about 20 rows ans 40 columns that I want to print on paper. I tried the table.print() method but that doesn't work, I just get one big empty cell on the paper. I tried an example from another site and that one works perfectly ( Does anyone know what's going wrong Is my table too large for the paper and do I need to resize it, and if so how
JTable printing problem   (654 Views)
I have sample of JTable with data that i would like to be right aligned, also orange background color cell renderer is applied, and font is set to be Tahoma BoldItalic with font size of 13. Problems that arise are, grid lines are over cell text, and also applied background color looks strange when PDF printer is used and document is zoomed. Interesting thing is that when font is set to be even grid lines doesn't intersect cell text. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.JTable.PrintMode; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; public class TablePrintTest extends JFrame { private static final long serialVersionUID = 1L; private static final Object[] COLUMN_NAMES = { "Column1", "Column2", "Column3" }; private static final Object[][] CELL_VALUES = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; private JButton printButton; private JTable table; public TablePrintTest() { super("TablePrintTest"); createGui(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void createGui() { table = new JTable(new DefaultTableModel() { private static final long serialVersionUID = 1L; @Override public Class getColumnClass(int columnIndex) { return Number.class; } @Override public int getColumnCount() { return COLUMN_NAMES.length; } @Override public int getRowCount() { return CELL_VALUES.length; } @Override public String getColumnName(int column) { return COLUMN_NAMES[column].toString(); } @Override public Object getValueAt(int row, int column) { return CELL_VALUES[row][column]; } }); table.setDefaultRenderer(Number.class, new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel label = (JLabel) super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); label.setHorizontalAlignment(SwingConstants.RIGHT); return label; } public java.awt.Color getBackground() { return; }; }); table.setFont(new Font("Tahoma", Font.ITALIC | Font.BOLD, 13)); printButton = new JButton("Print"); printButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Printable printable = table.getPrintable(PrintMode.NORMAL, null, null); PrinterJob pJob = PrinterJob.getPrinterJob(); pJob.setPrintable(printable); if (pJob.printDialog()) { try { pJob.print(); } catch (PrinterException e1) { e1.printStackTrace(); } } } }); JPanel contentPane = new JPanel(new BorderLayout()); contentPane.add(printButton, BorderLayout.NORTH); contentPane.add(new JScrollPane(table), BorderLayout.CENTER); setContentPane(contentPane); pack(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new TablePrintTest().setVisible(true); } }); } }
Problem in printing JTable values   (611 Views)
Dear Friends, I have to print the JTable values (on paper using print dialogue box). I'm using jtableObj.print to print the table values. But jtableObj.print takes more time to print the table values because it prints the values as a image(approximately 5 mins to print 10 pages). My code is , boolean complete = tableObj.print(mode, header, footer, showPrintDialog, null, interactive, null);
problems the program   (173 Views)
I am having problems with this program. When I run javac I am getting e errors about illegal start of expression. import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Calculator2 extends JFrame implements ActionListener { private JPanel panelAdder; private JLabel labela; private JLabel labelt; private JLabel labelr; private JTextField textFieldAmount; private JTextField textFieldTerm; private JTextField textFieldRate; private JTextField textFieldResult; private JButton buttonCalc; private JButton buttonClear; public Calculator2() { super("Calculator"); initComponents(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); pack(); // Add Listeners buttonCalc.addActionListener(this); buttonClear.addActionListener(this); } public void initComponents() { //Initialize Components panelAdder = new JPanel(); labela = new JLabel("Amount"); textFieldAmount = new JTextField(); labelt = new JLabel("Term"); textFieldTerm = new JTextField(); labelr = new JLabel("Rate"); textFieldRate = new JTextField(); textFieldResult = new JTextField(); button = new JButton("Calculate"); JTextFieldClear = new JTextField(); button = new JButton("Clear"); button = new Jbutton("Exit"); } public void actionPerformed(ActionEvent event) { Object source = event.getSource (); if (source == buttonCalc); { setResultValue(); } if (source == buttonClear); { newJTextField (""); } //Set Object Attributes textFieldResult.setEditable(false); textFieldResult.setColumns(8); textFieldAmount.setColumns(6); textFieldTerm.setColumns(2); textFieldRate.setColumns(2); Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); // add the components to the panel panelAdder.add(labela); panelAdder.add(textFieldAmount); panelAdder.add(labelt); panelAdder.add(textFieldTerm); panelAdder.add(labelr); panelAdder.add(textFieldRate); panelAdder.add(textFieldResult); contentPane.add(panelAdder); setVisible(true); [B]public void setResultValue(); [/B]{ double amount = Double.parseDouble (textFieldAmount.getText()); double rate = Double.parseDouble (textFieldRate.getText()); double term = Integer.parseInt(textFieldTerm.getText()); double result = amount * ( rate * Math.pow ( ( 1 + rate ), term ) ) / ( Math.pow( ( 1 + rate ), term ) - 1 ); textFieldResult.setText(Double.toString(result)); } public static void main(String[] arguments) { Calculator frame = new Calculator(); } }
JTabbedPane problems - not loading correctly   (188 Views)
I think i don't have something set correctly, but when I try to use JTabbedPanes it never loads correctly. If I have 3 tabs, tab 3 loads up first and I have to select all the tabs at least once before it works correctly. Here is an example of what i mean. I used this program written by Dave Marshall to see where i was messing up, but i get the same problem when i run it.m Any help would be great! -------------------------- import java.awt.*; import javax.swing.*; class TabbedPaneExample extends JFrame { privateJTabbedPane tabbedPane; privateJPanelpanel1; privateJPanelpanel2; privateJPanelpanel3; public TabbedPaneExample() { setTitle( "Tabbed Pane Application" ); setSize( 300, 200 ); setBackground( Color.gray ); JPanel topPanel = new JPanel(); topPanel.setLayout( new BorderLayout() ); getContentPane().add( topPanel ); // Create the tab pages createPage1(); createPage2(); createPage3(); // Create a tabbed pane tabbedPane = new JTabbedPane(); tabbedPane.addTab( "Page 1", panel1 ); tabbedPane.addTab( "Page 2", panel2 ); tabbedPane.addTab( "Page 3", panel3 ); topPanel.add( tabbedPane, BorderLayout.CENTER ); } public void createPage1() { panel1 = new JPanel(); panel1.setLayout( null ); JLabel label1 = new JLabel( "Username:" ); label1.setBounds( 10, 15, 150, 20 ); panel1.add( label1 ); JTextField field = new JTextField(); field.setBounds( 10, 35, 150, 20 ); panel1.add( field ); JLabel label2 = new JLabel( "Password:" ); label2.setBounds( 10, 60, 150, 20 ); panel1.add( label2 ); JPasswordField fieldPass = new JPasswordField(); fieldPass.setBounds( 10, 80, 150, 20 ); panel1.add( fieldPass ); } public void createPage2() { panel2 = new JPanel(); panel2.setLayout( new BorderLayout() ); panel2.add( new JButton( "North" ), BorderLayout.NORTH ); panel2.add( new JButton( "South" ), BorderLayout.SOUTH ); panel2.add( new JButton( "East" ), BorderLayout.EAST ); panel2.add( new JButton( "West" ), BorderLayout.WEST ); panel2.add( new JButton( "Center" ), BorderLayout.CENTER ); } public void createPage3() { panel3 = new JPanel(); panel3.setLayout( new GridLayout( 3, 2 ) ); panel3.add( new JLabel( "Field 1:" ) ); panel3.add( new TextArea() ); panel3.add( new JLabel( "Field 2:" ) ); panel3.add( new TextArea() ); panel3.add( new JLabel( "Field 3:" ) ); panel3.add( new TextArea() ); } // Main method to get things started public static void main( String args[] ) { // Create an instance of the test application TabbedPaneExample mainFrame= new TabbedPaneExample(); mainFrame.setVisible( true ); } }
JScrollPane and paint method problems   (191 Views)
Currently, I'm trying to make a program to handle double elimination brackets for a team tournament. One of my classes involves overwritting the paint method in order to display the brackets. The code is as follows: public void paint(Graphics g) { super.paint(g); drawPortion(bracket.getBracket(), getWidth()/2, 10, bracket.getDegree(), g); } private void drawPortion(BinaryTreeNode b, int x, int y, int degree, Graphics g) { drawPortionRecursive(bracket.getBracket(), getWidth()/2, 10, degree, g, 1); }
printing on A4 paper   (670 Views)
The paper object creates a letter sized piece of paper with one inch margins. Is there any way to set different margins to allow a page designed to fit on letter to also print on A4 by reducing the margins Or any other ideas ------------------
JTable related problems   (184 Views)
I am using JTable with 3 columns. I have added table to JScrollPane. I have also added scrollbars to table, and I add rows dynamically ,now My problems are - 1) I want my column should take size equal to highest width of column contents. 2) I want to select column when I click on column and press control key. I have added selection model to table. 3) My table should have white background. I have tried to set background of table as well as scrollpane but its not working. any help....
layout problems   (179 Views)
pls refer to the code below:- import java.awt.*; import java.awt.event.*; import java.sql.*; public class PhoneBook1 extends Frame { //this class creates 2 textfields for name and ph no entering n adds panel String name; String myname; ResultSet rs;TestEventPanel pt;Statement stmt;PreparedStatement ps; Label la;Label lc; Connection con ;LbPanel lb; GridBagLayout gridbag;GridBagConstraints constraints; PhoneBook1(){ setLayout(new FlowLayout()); pt=new TestEventPanel(); add(pt); frameLocation(); // redSlider=new Scrollbar(Scrollbar.VERTICAL,0,0,100,1,10); //add(redSlider); addWindowListener (new WindowAdapter() { public void windowClosing(WindowEvent e) { // System.exit(0); dispose(); } } ); constraints = new GridBagConstraints(); constraints.gridx = 0; //constraints.gridy = 4+i;RELATIVE ; // i++; gridbag = new GridBagLayout(); ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand()=="SAVE"){; createTable(myname); String nam="name "; myname=nam.concat(myname); System.out.println(myname); // la=new Label(myname); // add(la); validate(); } } } ); pt.view.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand()=="view"){ //; viewPhoneBook(); // System.out.println(myname); // lc=new Label(myname); // add(lc); validate(); } } } ); } //end constructor public void createTable(String x){ name=x; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc dbc:acodbc","",""); stmt=con.createStatement(); storePhone(name); // viewPhoneBook(); stmt.close(); con.close(); System.out.println("table PHONEDIARY created"); } catch(Exception e) { e.printStackTrace(); } } //end createTable() // name=tn.paramString() ; public void frameLocation(){ Dimension d = getToolkit().getScreenSize(); setLocation(d.width/4,d.height/3); setTitle("PhoneBook"); setSize(400,400); setVisible(true); }//end framelocation public void storePhone(String x){ myname=x; try{ String sql="INSERT INTO PHONEBOOK(NAME)VALUES()"; ps=con.prepareStatement(sql); ps.setString(1,myname); ps.executeUpdate(); // stmt.executeUpdate("INSERT INTO PHONEBOOK VALUES(" + myname + ",236821)"); } catch(Exception e){} } public void viewPhoneBook(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc dbc:acodbc","",""); stmt=con.createStatement(); rs=stmt.executeQuery("SELECT* from PHONEBOOK"); while( { Label ld=new Label(rs.getString(1)+" "+rs.getInt(2)); constraints = new GridBagConstraints(); constraints.gridx = 0; //constraints.gridy = 4+i;RELATIVE ; // i++; gridbag = new GridBagLayout(); //setLayout(gridbag);*/ // Panel p1=new Panel(); // add(p1); // p1.add(ld); add(ld); gridbag.setConstraints(ld, constraints); } }catch(Exception e){} }//end method viewphonebook public static void main(String st[]){ PhoneBook1 p=new PhoneBook1(); } } and the code for a panel is:- import java.awt.*; import java.awt.event.*; public class TestEventPanel extends Panel { Button view,b2; Button save;TextField tn; public TestEventPanel(){ super(); setLayout(new FlowLayout()); setBackground(new Color(0).pink); Label ln=new Label("name"); tn=new TextField("name"); Label lp=new Label("PhoneNo"); TextField tp=new TextField(15); save=new Button("SAVE"); add(ln); add(tn); add(lp); add(tp); add(save); view = new Button("view"); add(view); b2 = new Button("delete"); add(b2); } public static void main(String st[]){ TestEventPanel p=new TestEventPanel(); } } In this i create 2 textfields and two buttons.When i press the button it fetches some text stored in the MS Acess and displays it on the frame When i run the panel(TestEventPanel) appears with components on it as flowlayout.But the data(text) from the database is also presented as label in flowlayout manner.However i had given the gridbag layout for its laying. i want the panel with textfield and button to be presented as flowlayout and rest as gridbag in a vertical line.When i comment setLayout(new FlowLayout()); in the constructor PhoneBook1() Im not able to view the data from database why
printing html and images using JEditorPane   (533 Views)
hi i am working on printing multiple html and images(png) in a single batch.. i am able to print all in a single batch if html files are single page files but if they are multipage files i am unable to print them. i am rendering html to a JEditorPane. i can print multiple multipage html files in a single batch but unable to do html files and images in a single batch .. anyone can help me thanx in advance -if you want i can provide code bye madhu
printing data from JEditor Pane   (440 Views)
I have a program in which the data is shown in JEditor Pane. I have used HTMl tags to get the deed format. Now i want to print it. how should i proceed :roll:
printing html file   (543 Views)
hello, i have a html file. i want to print it. i using jeditorpane for showing the html file. because html file is large enough that i cannot show it whole in jeditorpane. so i used the container jscrollpane. when i want to print the document showing in the jscrollpane it print only the current shwing document not the whole document. please help me to solve this.
printing jframe content in core java   (508 Views)
I want to print Jframe like our word document. I have one jframe on jframe i have Jpanel ond on that panel i have j label . In jlabel i written a letter i want to print that letter so how can I print that letter.
JTable printing . . .   (455 Views)
I have customized the column widths of a JTable to display properly on screen. But this size of the JTable doesn't looks good on the print when i set the JTable.PrintMode.FIT_WIDTH option, which produces small table on paper. But when the column widths are reduced on screen it looks very good on paper, and losses its look on screen.So, i want to make the table to fit width both on the screen and paper also. How to achieve this Thank you.