Results 1 to 2 of 2
  1. #1
    eLancaster is offline Member
    Join Date
    Jan 2011
    Posts
    93
    Rep Power
    0

    Default Why can't I see the images in the buttons?

    I am writing this flashcard application where there's a toolbar panel at the bottom. The toolbar contains buttons with images and text in them. When the application runs, the text is visible but not the images. Where am I going wrong?

    Java Code:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.util.LinkedList;
    
    import javax.swing.AbstractButton;
    import javax.swing.GroupLayout;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    
    
    public class Flashcards implements ActionListener {
    	JFrame window;
    	JLabel statusLabel;
    
    	//Constructor
    	public Flashcards()
    	{
    		createUserInterface();
    	}
    	
    	//Public Methods
    	
    	
    	//Private Methods.
    	private void createUserInterface()
    	{
    		//Basic UI
    		window = new JFrame("Flashcards");
    			window.setSize(600,300);
    			window.setVisible(true);
    			window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    				
    			
    		JPanel mainPanel = new JPanel();
    			window.getContentPane().add(mainPanel, BorderLayout.CENTER);
    		
    		statusLabel = new JLabel("Label");
    			mainPanel.add(statusLabel);
    		
    		JPanel toolbar = new JPanel();
    			//toolbar layout and buttons.
    			window.getContentPane().add(toolbar, BorderLayout.SOUTH);
    			
    		JMenuBar menubar = new JMenuBar();
    			window.setJMenuBar(menubar);
    		
    		//The toolbar and the grouplayout
    			Icon[] arrayOfButtonImages = {new ImageIcon("/Images/Open.png")};
    			
    			JButton btnOpenList = new JButton("Open", arrayOfButtonImages[0]);
    				btnOpenList.setVerticalTextPosition(AbstractButton.CENTER);
    				btnOpenList.setHorizontalTextPosition(AbstractButton.CENTER);
    				btnOpenList.setActionCommand("Open");
    				btnOpenList.addActionListener(this);
    			
    			GroupLayout toolbarLayout = new GroupLayout(toolbar);
    			toolbar.setLayout(toolbarLayout);
    			
    			toolbarLayout.setHorizontalGroup(
    			toolbarLayout.createSequentialGroup()
    				.addComponent(btnOpenList);
    				
    			
    			toolbarLayout.setVerticalGroup(
    					toolbarLayout.createParallelGroup()
    						.addComponent(btnOpenList);
    
    	}
    	public void actionPerformed(ActionEvent event)
    	{
    		System.out.println(String.format("%s", event.getActionCommand()));
    		statusLabel.setText(String.format("%s", event.getActionCommand()));
    	}
    	
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		new Flashcards();
    	}
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 0
    Last Post: 12-16-2010, 05:14 PM
  2. Replies: 4
    Last Post: 12-16-2010, 04:32 PM
  3. Help: Displaying Images AND Adding Buttons
    By Rhez in forum New To Java
    Replies: 2
    Last Post: 08-05-2010, 06:19 AM
  4. Replies: 2
    Last Post: 04-30-2010, 03:06 AM
  5. Changing images by clicking arrow buttons. help?
    By ashton in forum New To Java
    Replies: 3
    Last Post: 02-08-2009, 11:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •