Problem in printing Jpanel Data


I am working on a swings application I have a Jpanel, I am facing serious problem with printing this JPanel data with "card printer". This is working fine when i using paper color printer but when i am using card printer its printing nothing. I have tested the printer using some Images and it is printing fine when i print any Image directly but using my application having problem the card printer not receiving any data while the paper printer is printing fine. Any one faced this before or anyone please help me out. This is my code:

private void printCard(){ PrinterJob printjob = PrinterJob.getPrinterJob(); printjob.setJobName(" CUSTOMER CARD "); printjob.setPrintable (new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum){ pf.setOrientation(PageFormat.LANDSCAPE); if (pageNum > 0){ return Printable.NO_SUCH_PAGE; } Graphics2D g2 = (Graphics2D) pg; g2.translate(pf.getImageableX(), pf.getImageableY()); g2.translate( 0f, 0f ); jLayeredPane2.paint(g2); return Printable.PAGE_EXISTS; } }); if (printjob.printDialog() == false) return; try { printjob.print(); } catch (PrinterException ex) { System.out.println("NO PAGE FOUND."+ex); } }
Posted On: Monday 22nd of October 2012 02:22:17 AM Total Views:  351
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




JSTL tag library problem.

I am not able to run a jsp page which has some JSTL code . I am using sun one web server 6.1.While running it always complains about some appsolute url problem.I had included taglib ective in the web.xml too.
VIEWS ON THIS POST

115

Posted on:

Thursday 18th October 2012
View Replies!

Cursor problem when moving around the frames

This is the problem which can be easily solvable. But, I'm not getting right point to look into it. When I set the cursor to busy state on one of the frames in my application under process of a task, I move the cursor out of this frame and take back again into this. Here my cursor is changed to default cursor( which I should get after completing my task process). After a few seconds it again goes to busy state. Finally after my task is completed it comes to normal state which is expected. I wonder why the cursor is changing to normal state and again to busy state after I move it into the frame. How this problem be solved Please help me into this.
VIEWS ON THIS POST

134

Posted on:

Thursday 18th October 2012
View Replies!

Application path problem

Hi , I'm having a problem with file paths. Basically, if you launch the application in Windows by double-clicking an associated file, the application seems to take the path as that of the file, not the actual application. If I load the application normally, it takes the correct path. To illustrate: /application/myexe.exe /application/myimage.jpg double clicking myexe.exe loads the image fine because I use: File file = new File(""); file.getAbsolutePath() + File.separator + "myimage.jpg"; but if I load the application by double-clicking a file: /desktop/file.txt file.getAbsolutePath() returns /desktop, not /application. So it can't find the image file then because it thinks it should be at /desktop. Is there any way to get around this
VIEWS ON THIS POST

150

Posted on:

Thursday 18th October 2012
View Replies!

JTable Cell data validation/blank cell problem

I am fairly new to Swings. I have a JTable that has to do some validations before its data is saved: (1) Each row of the Table allows values within a set range ex:0.5 to 100 (2) The cell may allow blank (later replaced before save with the lower range value) cell data will be Float data. My questions: (a) Right now I am iterating through JTable cells and checking each row-wise cell to see if they are within range. What is the correct way to do such validations (b) JTable by default is not allowing me to leave the cell blank (the focus remains on the cell if I try to leave it blank). How can I allow blank cell entries (c) If user enters an invalid data (say a String) in the cell that expects Float value, the text stays in the cell even though I clear the TableModel and repopulate the data. Any idea how to get over this [ October 07, 2004: Message edited by: Yash Sharma ]
VIEWS ON THIS POST

149

Posted on:

Thursday 18th October 2012
View Replies!

Table Row Selection problem while adding any Image in a JTable

I am adding an Image in JTable public class BrowserLabelCellRenderer extends AbstractCellEditor implements TableCellRenderer, TableCellEditor,ActionListener
VIEWS ON THIS POST

184

Posted on:

Sunday 21st October 2012
View Replies!

problem in executing swing application

hello i'm facing a strange problem while ruuning a swing applet program. my program is compiling alright, but wenevr i mtrying to run it from command prompt, it's showing the following exception:: "Exception in thread"main" java.lang.NoSuchMethodError: main" even in netbeans ide it's showing the same thing where m i going wrong\t
VIEWS ON THIS POST

137

Posted on:

Sunday 21st October 2012
View Replies!

JTable inside JScrollPane - background coloring problem

I have a situation with a table that's narrower and shorter than the enclosing scroll pane's viewport, and column auto-resizing is turned off, so there's empty space below and to the right of the table. I'd like to fill the empty space with a single background color. I can fill in the bottom using scrollPane.setBackground(), and I can set most of the right side using scrollPane.getViewport().setBackground(). But I'm still left with an uncolored strip to the right of the table's column headers. I've tried using setBackground on the scroll pane's enclosing panel, and also tried using scrollPane.setColumnHeaderView() to force a new colored JPanel, but neither method has worked. Is there any way to fill in that strip right of the table's column headers Below is the code I'm using, a slight variation of TableDemo.java from Oracle's Swing Example set.
VIEWS ON THIS POST

174

Posted on:

Monday 22nd October 2012
View Replies!

Display problem in JFrame

I am developing on application in swing. I want to display some big data on JFrame. If I display a big string on frame, it does not go to next line when it ends at the current line as it works on pixel. What is the solution for this. How people display data generatlly. In my case I have 5 fields. something like key value. but value is big string. Please help on this.
VIEWS ON THIS POST

120

Posted on:

Monday 22nd October 2012
View Replies!

JEditorPane HTML parsing problem with about CSS

my I have a problem about JEditorPane html source. When I read html source to my editor it changes html source. How can make it unchangable or what is the reason of problem There is parsing problem style='font-size:11.0pt;font-family:"Palatino Linotype"' changes to font face="Palatino Linotype" size="11.0pt". My input HTML: JEditorPane Test Test
VIEWS ON THIS POST

157

Posted on:

Monday 22nd October 2012
View Replies!

Printing invisible JTable containing JTables - problem

I am trying to print an invisivle JTable that contains inner JTables (nested). The outer JTable prints as it should, but for some reason the inner JTables header is never printed, even though everything else of the inner JTables is printed as it should, and that is where the problem is. I have tried everything I can think of without solving it. I would be happy if someone could help me with this. Thatnks in advance for any help. In my code the table is made visible after it is printed to show what it should be like. Here's my example code: import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.print.PrinterException; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; import javax.swing.table.TableColumn; public class TestNestedJTable2 extends JFrame{ private static final long serialVersionUID = -722808327091366767L; private JTable mainTable; private JTable leftTable; private JTable rightTable; private Object[][] tableList; private Container container; private String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; private Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)}, }; private String[] columnNames2 = {"", "Last Name", "Group", "Year"}; private Object[][] data2 = { {false, "Li", "Tiger", new Integer(1997), }, {false, "Roy", "Lion", new Integer(1996)}, {false, "Lee", "Dragon", new Integer(1989)}, {false, "Jones", "Lion", new Integer(1981)}, {false, "Lam", "Dragon", new Integer(1980)}, }; private String[] names = {"sdf", "sdf", "dfs"}; public TestNestedJTable2(){ container = this.getContentPane(); leftTable = new JTable(data, columnNames); rightTable = new JTable(data2, columnNames2); leftTable.getTableHeader().setVisible(true); rightTable.getTableHeader().setVisible(true); leftTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); leftTable.setSize(leftTable.getPreferredSize()); JTableHeader header = leftTable.getTableHeader(); header.setSize(header.getPreferredSize()); rightTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); rightTable.setSize(rightTable.getPreferredSize()); header = rightTable.getTableHeader(); header.setSize(header.getPreferredSize()); tableList = new Object[1][]; tableList[0] = new Object[3]; tableList[0][0] = leftTable; tableList[0][1] = rightTable; tableList[0][2] = "dfgfdg"; mainTable = new JTable(new DefaultTableModel(tableList, names)); TableColumn tc = mainTable.getColumnModel().getColumn(0); tc.setCellRenderer(new CustomTableCellRenderer(leftTable)); tc = mainTable.getColumnModel().getColumn(1); tc.setCellRenderer(new CustomTableCellRenderer(rightTable)); mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); DefaultTableColumnModel colModel = (DefaultTableColumnModel) mainTable.getColumnModel(); TableColumn col = colModel.getColumn(0); col.setPreferredWidth(leftTable.getSize().width + 2); col.setWidth(leftTable.getSize().width + 2); col = colModel.getColumn(1); col.setPreferredWidth(rightTable.getSize().width + 2); col.setWidth(rightTable.getSize().width + 2); mainTable.setRowHeight(leftTable.getPreferredSize().height+leftTable.getTableHeader().getPreferredSize().height+1); mainTable.setMinimumSize(mainTable.getPreferredSize()); mainTable.setSize(mainTable.getPreferredSize()); header = mainTable.getTableHeader(); header.setSize(header.getPreferredSize()); try { mainTable.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException e) { // TODO Auto-generated catch block e.printStackTrace(); } container.add(new JScrollPane(mainTable)); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); setSize(800,800); setVisible(true); } class CustomTableCellRenderer extends DefaultTableCellRenderer { private static final long serialVersionUID = 4415155875184525824L; JTable table; CustomTableCellRenderer(JTable table){ this.table=table; this.table.setOpaque(true); this.table.setAlignmentY(JTable.LEFT_ALIGNMENT); } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { this.table=(JTable)value; this.table.setPreferredScrollableViewportSize(this.table.getSize()); JScrollPane jCrollPane = new JScrollPane(this.table); jCrollPane.setBorder(BorderFactory.createEmptyBorder()); jCrollPane.getViewport().setSize(new Dimension(this.table.getSize().width-1, this.table.getSize().height+16)); return jCrollPane; } } /** * @param args */ public static void main(String[] args) { new TestNestedJTable2(); } }
VIEWS ON THIS POST

138

Posted on:

Monday 22nd October 2012
View Replies!

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 .
VIEWS ON THIS POST

339

Posted on:

Monday 22nd October 2012
View Replies!

Animation problem with swing

I'm trying to create an applet of a rain storm. i've already have the program working, pretty much. the only problem that i have is... well let me explain it this way: RainDrop is the class that has the methods to draw the raindrop to the screen, move it down the screen, and destroy it when it reaches the bottom of the frame. (Note: if you want 20 raindrops on the screen, you need 20 instances of RainDrop by the way i have it setup.) each instance of RainDrop implements Runnable. the run methods of each class will paint a blue oval to the screen, move the coordinates down, then call repaint(). this paints to an image, ALL instances of raindrop paint to one image, then the call to paint well paints that image onto the frame, double buffering it. the problem i'm having is the stupid Thread system in java. here's an example of what i mean: 2 instances of raindrop are in the part of the thread sequence where it paints the raindrop to the screen. well, at the same time, another instance of raindrop is executing the command to draw a rectangle the size of the screen, to cover up the other traces of the left behinds raindrop images, making the raindrops look animated. what i'm basically getting at is that because of this system, the final result is that the raindrops flicker all the way down the screen, and i'm pretty sure that sun has created a class or a method that i have not seen yet that will take care of this problem. PLEASE HELP!!!
VIEWS ON THIS POST

127

Posted on:

Monday 22nd October 2012
View Replies!

Interdepenent JSpinners problem

I have two JSpinner which represent the width and the height of an image. These values can be manipulated freely unless "Maintain ratio" checkbox is selected. Then, when e.g. width changes, the height value is changed accordingly automatically using the previously calculated size ratio for the image. This little program represents the idea (I hard-coded the size ratio): import java.awt.FlowLayout; import javax.swing.*; import javax.swing.event.*; public class SpinnerTest extends JFrame{ JSpinner widthSpinner = new JSpinner(); JSpinner heightSpinner = new JSpinner(); JCheckBox ratioBox = new JCheckBox("MaintainRatio"); double ratio = 0.85; public SpinnerTest() { setLayout(new FlowLayout()); getContentPane().add(ratioBox); getContentPane().add(widthSpinner); getContentPane().add(heightSpinner); widthSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if(ratioBox.isSelected()){ Integer width = (Integer) widthSpinner.getValue(); int w = width.intValue(); heightSpinner.setValue((int)(w/ratio)); } } }); heightSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if(ratioBox.isSelected()){ Integer height = (Integer) heightSpinner.getValue(); int h = height.intValue(); widthSpinner.setValue((int)(h*ratio)); } } }); } public static void main(String[] args) { SpinnerTest frame = new SpinnerTest(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.setSize(300, 200); frame.setLocationRelativeTo( null ); frame.setVisible(true); } }
VIEWS ON THIS POST

130

Posted on:

Monday 22nd October 2012
View Replies!

Cardlayout problem

wow its a long time since i wrote a message here (or worked on my project at all) but i decided enough was enough i need to set aside some time to work on it. so i have done and i have run into a brick all after about an hour my problem is to do with the show() class in the cardlayout. Im hoping i've cut my code down enough for you (it still shows the same error) import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.GraphicsEnvironment; import java.awt.LayoutManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class Main { public static JPanel passwordPanel(){ JPanel passwordPanel = new JPanel(); JLabel test = new JLabel("hoping this works"); passwordPanel.add(test); return passwordPanel; } public static JPanel encryptionPanel(){ JPanel encryptionPanel = new JPanel(); JLabel test = new JLabel("test"); encryptionPanel.add(test); return encryptionPanel; } public static JPanel selectToolPanel() { final JPanel selectToolPanel = new JPanel(); LayoutManager lay = new BoxLayout(selectToolPanel, BoxLayout.PAGE_AXIS); selectToolPanel.setLayout(lay); class pageSwitch implements ActionListener { public void actionPerformed(ActionEvent select) { CardLayout cl = (CardLayout)(masterToolPanel().getLayout()); cl.show(masterToolPanel(), select.getActionCommand()); } } JButton test = new JButton("TEST"); JButton test2 = new JButton("TEST2 has a different size"); test.addActionListener(new pageSwitch()); test2.addActionListener(new pageSwitch()); selectToolPanel.add(test); selectToolPanel.add(Box.createRigidArea(new Dimension(0,10))); selectToolPanel.add(test2); return selectToolPanel; } public static JPanel masterToolPanel(){ final JPanel switchPanel = new JPanel(); switchPanel.setLayout(new CardLayout()); JPanel card1 = passwordPanel(); JPanel card2 = encryptionPanel(); switchPanel.add(card1, "TEST"); switchPanel.add(card2, "TEST2 has a different size"); return switchPanel; } public static JPanel masterLayout() { JPanel masterPanel = new JPanel(); LayoutManager lay = new BorderLayout(); masterPanel.setLayout(lay); masterPanel.add(masterToolPanel(), BorderLayout.CENTER); masterPanel.add(selectToolPanel(), BorderLayout.WEST); return masterPanel; } public static void centerScreen(JFrame frame){ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); int x = ge.getMaximumWindowBounds().width; int y = ge.getMaximumWindowBounds().height; frame.setSize(Math.min(x, 800), Math.min(y, 500)); frame.setLocation((x - frame.getWidth()) / 2,(y - frame.getHeight()) / 2); } public static void createAndShowGUI(){ JFrame frame = new JFrame("Hacking Utility"); frame.add(masterLayout()); frame.setResizable(false); centerScreen(frame); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
VIEWS ON THIS POST

131

Posted on:

Monday 22nd October 2012
View Replies!

container Repaint problem

In my application i am using the same window and change the components at various button events using remove(),revalidate() and repaint(). in this code i am i have three different methods 1. initialWindow() 2. actionPerformed() in SubmitHandler class (inner class to SCJPTestApplication class) 3. actionPerformed() in BeginTest class (inner class to SCJPTestApplication class) the initialWindow () method displays the initial window which asks the user to select and submit the chapter from which he/she expects the test. On clicking the submit button on the initial window the actionPerformed method in the SubmitHandler listener class is invoked which removes the current components, revalidates, adds new components (a button called "Begin Test" and a label showing the chapter name selected for the test). DURING THE RUN THE PROGRAM WORKS PERFECTCLY TILL THIS POINT. Clicking the "Begin Test" button calls the actionPerformed() in the BeginTest class which removes the current components, adds new ones (a non-editable JTextpane holding the current question, few radiobuttons for options, and the submit button) and repaints the JPanel holding the components. The problem is that the window does not get Repainted. I have put several println() statemnts to check on the console if this actionPerformed method in the BeginTest class is executing. On the console it shows complete execution of the actionPerformed method. but the window is not repainted. I dont know why below given is the code. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package testWindow; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextPane; import javax.swing.SwingUtilities; /** * * @author hp */ public class SCJPTestApplication { private JFrame window; Container content; private JLabel qString; private JPanel question; private JButton submit; private JRadioButton op; private JList chlist; private JTextPane qPane; private String chapterSelected; private SCJPTestGenerator tg; private int qIndex; SCJPTestApplication(){ tg = new SCJPTestGenerator(); } void initialWindow(){ System.out.println("Initial Window"); window = new JFrame("SCJP 1.5 Test"); window.setBounds(100,100, 400,300); content = window.getContentPane(); String topics[]=tg.generateTopicList(); chlist = new JList(topics); submit = new JButton("Submit"); question = new JPanel(); question.add(new JLabel("Please Select the Chapter")); question.add(chlist); question.add(submit); content.add(question); submit.addActionListener(new SubmitHandler()); window.setVisible(true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } class SubmitHandler implements ActionListener{ public void actionPerformed(ActionEvent e){ System.out.println("Submit Window"); chapterSelected = (String)chlist.getSelectedValue(); question.remove(); question.revalidate(); question.add(new JLabel(chapterSelected)); submit.setText("Begin Test"); question.add(submit); submit.addActionListener(new BeginTest()); question.repaint(); } } class BeginTest implements ActionListener{ ArrayList test ; Question q; BeginTest(){ test = tg.generateChapterTest(chapterSelected); qPane = new JTextPane(); } public void actionPerformed(ActionEvent e){ question.remove(); question.revalidate(); if(qIndex
VIEWS ON THIS POST

161

Posted on:

Monday 22nd October 2012
View Replies!

Caps Action problem

i've this swing aplication that has a label inside a jPanel; i want this label to get enabled if caps lock is on some code i'm using: //invoked inside aplication constructor capsAction = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { JPanel rodape = (PanelRodape)e.getSource(); JLabel labelCaps = (JLabel)rodape.getComponent(0); Toolkit toolkit = Toolkit.getDefaultToolkit(); labelCaps.setEnabled(toolkit.getLockingKeyState(KeyEvent.VK_CAPS_LOCK)); } }; //some code for panel creation:(rodape is the panel containing the label) rodape.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(CAPS_LOCK), CAPS_SELECCIONADO);// CAPS_SELECCIONADO means "clicked" rodape.getActionMap().put(CAPS_SELECCIONADO, capsAction);
VIEWS ON THIS POST

122

Posted on:

Monday 22nd October 2012
View Replies!

problem in printing to file (JSE 6)

I tried using printing support in JTextComponent, as provided in Java SE 6. The code I used is really simple: try { boolean complete = jTextArea1.print(); if (complete) { /* show a success message */ System.out.print("success"); } else { /*show a message indicating that printing was cancelled */ System.out.print("cancelled"); } } catch (PrinterException pe) { /* Printing failed, report to the user */ System.out.print("exception"); }
VIEWS ON THIS POST

331

Posted on:

Monday 22nd October 2012
View Replies!

problem in writing to file. Contents not refreshed automatically

hi, I am using the following code to write into a java properties file through the swings UI. I am trying to re open the UI after making write changes, and the contents written are not to be seen on the UI. I am using eclipse IDE and i need to manually open the file on which is asks me save changes. If i run the UI again, I m able to see the changes. What should i do to refresh the file contents and not save changes manually. File fileToWrite = new File("conf/ErrorCodes.properties"); // set the file property to be made writable fileToWrite.setWritable(true); PrintWriter fileWriter = new PrintWriter(new FileWriter(fileToWrite, false)); // write string contents containing all row data to file if (writable_String != null) { fileWriter.print(writable_String); } fileWriter.close();
VIEWS ON THIS POST

105

Posted on:

Monday 22nd October 2012
View Replies!

problems with groupLayout

I am using a groupLayout inside a JTabbedPane and while I am not getting errors during the development at runtime I am getting a whole slew of them. Below is the I am using for the groupLayout html_tab.setLayout(htmlLayout); htmlLayout.setHorizontalGroup( htmlLayout.createSequentialGroup() .addComponent(doct_type) .addComponent(body_tags_btn) .addComponent(tags_btn) .addComponent(table_btn) .addComponent(form_btn) .addComponent(list_btn) .addComponent(events_btn) // creates alignment vertically with two buttons //.addGroup(htmlLayout.createSequentialGroup() //.addGap(86, 86, 86) //, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE //.addContainerGap(441, Short.MAX_VALUE)) ); htmlLayout.setVerticalGroup( //htmlLayout.createSequentialGroup() htmlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(htmlLayout.createSequentialGroup() .addComponent(code_tab_menu, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(doct_type) .addComponent(body_tags_btn) .addComponent(tags_btn) .addComponent(table_btn) .addComponent(form_btn) .addComponent(list_btn) .addComponent(events_btn) //.addContainerGap(326, Short.MAX_VALUE)) ));
VIEWS ON THIS POST

103

Posted on:

Monday 22nd October 2012
View Replies!

What the heck!? JPanel background problem - weird!

Ok, so I got the background image working on my first window, then I went to add it to a second window and the weirdest thing happened. Two different applications (one called by the other), two different images (different names), but both windows display the same image. Here's the code: First application: class BackgroundPanel extends JPanel { Image image; public BackgroundPanel(int size[]) { try { image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("jeep03.jpg"), "jeep03.jpg")); size[0] = image.getWidth(null); size[1] = image.getHeight(null); } catch (Exception e) { /*handled in paintComponent()*/ } return; } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (image != null) g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),this); } }
VIEWS ON THIS POST

130

Posted on:

Monday 22nd October 2012
View Replies!