Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Adding background image to JDesktopPane
cs thiang
Greenhorn
Posts: 8
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How am I going to do that?
import java.awt.*; import java.net.URL; import java.util.Arrays; import javax.swing.*; import java.awt.event.*; import javax.swing.ImageIcon; import javax.swing.JMenuBar; public class mainPg extends JFrame { private JLabel statusBar = new JLabel(); private JMenuItem menuHelpAbout = new JMenuItem(); private JMenu menuHelp = new JMenu(); private JMenuItem menuFileExit = new JMenuItem(); private JMenu menuFile = new JMenu(); private JMenu menuSuper = new JMenu(); private JMenu menuAdmin = new JMenu(); private JMenuItem menuSuperdrop = new JMenuItem(); private JMenuItem menuSuperdrop2 = new JMenuItem(); private JMenuItem menuSuperdrop3 = new JMenuItem(); private JMenuBar menuBar = new JMenuBar(); private JPanel panelCenter = new JPanel(); private BorderLayout layoutMain = new BorderLayout(); private JDesktopPane desktop; private JMenuItem login = new JMenuItem(); private ActionMap actionMap1 = new ActionMap(); public adminResult aR = null; public finalist f = null; //public finalist f = new finalist(); //public votingPg vpg = null; //String[][] namelist = new String[8][2]; static int[] numvote = new int[8]; static int[] unsorted = new int[8]; private JMenuItem jMenuItem1 = new JMenuItem(); int j =0; int k =0; int l =0; int num; String name; boolean count; Class metaObject = this.getClass(); URL url = metaObject.getResource("images/superstar.jpg"); ImageIcon imageIcon = new ImageIcon(url); Image image = imageIcon.getImage(); public mainPg() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } globals.mp = this; } public static String announceResult(int avote) { String name = globals.test[avote]; return name; } public void visi(boolean b) { menuSuperdrop2.setEnabled(b); } public void visi2(boolean b2) { menuSuperdrop3.setEnabled(b2); } public void visi3(boolean b3) { login.setEnabled(b3); } private void jbInit() throws Exception { count = false; this.setJMenuBar(menuBar); this.getContentPane().setLayout(layoutMain); panelCenter.setLayout(null); this.setSize(new Dimension(645, 600)); this.setTitle("Project Sup3rStar"); menuFile.setText("File"); menuSuper.setText("Sup3rStar"); menuAdmin.setText("Administrator"); menuSuperdrop.setText("Finalist"); menuSuperdrop2.setText("Vote"); menuSuperdrop3.setText("Result"); menuFileExit.setText("Exit"); jMenuItem1.setText("Restart"); desktop = new JDesktopPane(); //a specialized layered pane login.setText("Login"); setContentPane(desktop); menuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { fileExit_ActionPerformed(ae); } } ); jMenuItem1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { jMenuItem1_ActionPerformed(ae); } } ); ..................................continues....
[ February 12, 2006: Message edited by: cs thiang ]
Michael Dunn
Ranch Hand
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing extends JFrame { MyDesktopPane dp = new MyDesktopPane(); JInternalFrame if1 = new JInternalFrame( "I-F1", true, true, true, true ); JInternalFrame if2 = new JInternalFrame( "I-F2", true, true, true, true ); JTextField[] tf = new JTextField[4]; JButton[] btn = new JButton[tf.length]; public Testing() { setLocation(300,200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel1 = new JPanel(new GridLayout(4,1)); JPanel panel2 = new JPanel(new GridLayout(4,1)); for(int x = 0; x < tf.length; x++) { tf[x] = new JTextField(5); panel1.add(tf[x]); btn[x] = new JButton("B"+(x+1)); panel2.add(btn[x]); } if1.setLocation(50,50); if2.setLocation(250,50); if1.getContentPane().add(panel1); if2.getContentPane().add(panel2); if1.pack(); if2.pack(); if1.setVisible(true); if2.setVisible(true); dp.add(if1); dp.add(if2); getContentPane().add(dp); setSize(400,300); setVisible(true); } public static void main(String[] args){new Testing();} } class MyDesktopPane extends JDesktopPane { Image img; public MyDesktopPane() { try { img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("Test.gif"), "Test.gif")); } catch(Exception e){}//do nothing } public void paintComponent(Graphics g) { super.paintComponent(g); if(img != null) g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this); else g.drawString("Image not found", 50,50); } }
Yesudas S Solomon
Greenhorn
Posts: 2
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Try this it will work fine...
private void setBackgroundImageDB() { try { String query = "select * from table_photos WHERE ModuleID = 12" ResultSet rs = DBUtils.executeQuery(query); if (rs.next()) { byte[] imageBytes = rs.getBytes("ModulePhoto"); if (imageBytes == null) { setBackgroundImageNonDB(); return; } ImageIcon img = new ImageIcon(imageBytes); jLabel1.setBounds(0, 0, (int) d.getWidth(), (int) d.getHeight()); jLabel1.setIcon(getScaledIcon(img, jLabel1)); } } catch (SQLException ex) { System.out.println("www.wordofgod.in :: Error on getting data from DB"); } } private void setBackgroundImageNonDB() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); Image img = new ImageIcon(getClass().getResource("/com/mycomp/mymodule/JesusChrist.jpg")).getImage(); jLabel1.setBounds(0, 0, (int) d.getWidth(), (int) d.getHeight()); jLabel1.setIcon(CommonUtils.getScaledIcon(new ImageIcon(img), jLabel1)); } public ImageIcon getScaledIcon(ImageIcon imageIcon,JLabel jLabel){ Image image = imageIcon.getImage().getScaledInstance(jLabel.getWidth(), jLabel.getHeight(), Image.SCALE_SMOOTH); imageIcon.setImage(image); return imageIcon; }
[ December 12, 2007: Message edited by: Yesudas S Solomon ]
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Displaying a JWindow
Adding background image to JDesktopPane?
Hello Dear, I want image in JInternalFrame in this code below please help......thanks regards
JMenuBar Rollover
JMenu Update
More...