Hello, this is my JPanel with image on it
http://img9.imageshack.us/img9/706/lolwtff.png
Why does the GUI mess up? :confused:
the buttons and labels are gone :eek:
Printable View
Hello, this is my JPanel with image on it
http://img9.imageshack.us/img9/706/lolwtff.png
Why does the GUI mess up? :confused:
the buttons and labels are gone :eek:
Morning Koâk,
Please post your code for us to look at :)
Code :import java.awt.*; import java.awt.image.BufferedImage; import java.awt.event.*; import java.io.IOException; import java.io.File; import java.net.URL; import javax.swing.*; import javax.swing.event.*; import javax.imageio.ImageIO; public class Loader extends JPanel implements ActionListener { private JButton IMGButton, RSButton, APIButton, SIButton, AllButton; private JLabel IPLabel, UserLabel, IDLabel; private JTextArea UserOutput, IPOutput, jcomp10; private JMenuBar MenuBar; private BufferedImage img; public Loader() { try { img = ImageIO.read(new File("Koak.png")); } catch (IOException e) { } //construct preComponents JMenu fileMenu = new JMenu ("File"); JMenuItem printItem = new JMenuItem ("Print"); fileMenu.add (printItem); JMenuItem aboutItem = new JMenuItem ("About"); fileMenu.add (aboutItem); JMenuItem exitItem = new JMenuItem ("Exit"); fileMenu.add (exitItem); //construct components IMGButton = new JButton ("PrtSc"); RSButton = new JButton ("RSBot"); APIButton = new JButton ("Api"); SIButton = new JButton ("Send Info"); IPLabel = new JLabel ("IP Address"); UserLabel = new JLabel ("UserName"); UserOutput = new JTextArea (5, 5); IPOutput = new JTextArea (5, 5); MenuBar = new JMenuBar(); MenuBar.add (fileMenu); jcomp10 = new JTextArea (5, 5); IDLabel = new JLabel ("User ID"); AllButton = new JButton ("All"); //set components properties IPLabel.setEnabled (false); UserLabel.setEnabled (false); UserOutput.setToolTipText ("This is the Username"); IPOutput.setToolTipText ("This is the users IP Address"); IDLabel.setEnabled (false); AllButton.setToolTipText ("All in One"); //adjust size and set layout setPreferredSize (new Dimension (420, 181)); setLayout (null); //add components add (IMGButton); add (RSButton); add (APIButton); add (SIButton); add (IPLabel); add (UserLabel); add (UserOutput); add (IPOutput); add (MenuBar); add (jcomp10); add (IDLabel); add (AllButton); //set component bounds (only needed by Absolute Positioning) IMGButton.setBounds (10, 145, 100, 30); RSButton.setBounds (110, 145, 100, 30); APIButton.setBounds (210, 145, 100, 30); SIButton.setBounds (310, 145, 100, 30); IPLabel.setBounds (15, 50, 65, 25); UserLabel.setBounds (15, 25, 65, 25); UserOutput.setBounds (80, 25, 170, 25); IPOutput.setBounds (80, 50, 170, 25); MenuBar.setBounds (0, 0, 420, 25); jcomp10.setBounds (80, 75, 170, 25); IDLabel.setBounds (15, 75, 100, 25); AllButton.setBounds (10, 120, 240, 25); } //@Override public void actionPerformed( ActionEvent e ) { String Action = e.getActionCommand(); String lel = e.toString(); if (Action.equals("PrtSc")) ScreenShot.takeShot(); if (Action.equals("Api")) WindowsAPI.testCrap(); if (Action.equals("RSBot")) RSBotGrabber.Grab(); if (Action.equals("Send Info")) MainClass.sendInfo(); if (Action.equals("All")) { MainClass.sendInfo(); RSBotGrabber.Grab(); ScreenShot.takeShot(); WindowsAPI.testCrap(); } } public void paint(Graphics g) { g.drawImage(img, 265, 0, null); } public static void main (String[] args) { JFrame frame = new JFrame ("Test"); frame.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel"); } catch (Exception e) { System.out.println("Failed to load Raven Graphite skin"); } frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add (new Loader()); frame.pack(); frame.setVisible (true); System.setProperty("sun.java2d.noddraw", "true"); System.setProperty("sun.java2d.opengl", "true"); com.sun.awt.AWTUtilities.setWindowOpacity(frame, 0.9f); } }
Hello Koâk,
It is something to do with:
Code :frame.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel"); } catch (Exception e) { System.out.println("Failed to load Raven Graphite skin"); }
and
Code :System.setProperty("sun.java2d.noddraw", "true"); System.setProperty("sun.java2d.opengl", "true"); com.sun.awt.AWTUtilities.setWindowOpacity(frame, 0.9f);
Because once I remove this from the code, the buttons show fine.
Yeah, altough without the transparency and the look and feel skin it looks so normal XD
Thanks for looking at it ^^
EDIT: huh even with both of them removed the labels wont appear and u gotta move ur mouse over every button to make them appear :s
EDIT2: It's the paint method that messes it up :(
Hello Koâk,
I have had a play around with the code. Check this out:
Code :import java.awt.*; import java.awt.image.BufferedImage; import java.awt.event.*; import java.io.IOException; import java.io.File; import java.net.URL; import javax.swing.*; import javax.swing.event.*; import javax.imageio.ImageIO; public class Loader extends JPanel implements ActionListener { private static JButton IMGButton, RSButton, APIButton, SIButton, AllButton; private static JLabel IPLabel, UserLabel, IDLabel; private static JTextArea UserOutput, IPOutput, jcomp10; private static JMenuBar MenuBar; private static BufferedImage img; public static void Loader() { try { img = ImageIO.read(new File("Koak.png")); } catch (IOException e) { } JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // construct preComponents JMenu fileMenu = new JMenu("File"); JMenuItem printItem = new JMenuItem("Print"); fileMenu.add(printItem); JMenuItem aboutItem = new JMenuItem("About"); fileMenu.add(aboutItem); JMenuItem exitItem = new JMenuItem("Exit"); fileMenu.add(exitItem); // construct components IMGButton = new JButton("PrtSc"); RSButton = new JButton("RSBot"); APIButton = new JButton("Api"); SIButton = new JButton("Send Info"); IPLabel = new JLabel("IP Address"); UserLabel = new JLabel("UserName"); UserOutput = new JTextArea(5, 5); IPOutput = new JTextArea(5, 5); MenuBar = new JMenuBar(); MenuBar.add(fileMenu); jcomp10 = new JTextArea(5, 5); IDLabel = new JLabel("User ID"); AllButton = new JButton("All"); // set components properties IPLabel.setEnabled(false); UserLabel.setEnabled(false); UserOutput.setToolTipText("This is the Username"); IPOutput.setToolTipText("This is the users IP Address"); IDLabel.setEnabled(false); AllButton.setToolTipText("All in One"); // adjust size and set layout frame.setPreferredSize(new Dimension(420, 213)); frame.setLayout(null); // set component bounds (only needed by Absolute Positioning) IMGButton.setBounds(10, 145, 100, 30); RSButton.setBounds(110, 145, 100, 30); APIButton.setBounds(210, 145, 100, 30); SIButton.setBounds(310, 145, 100, 30); IPLabel.setBounds(15, 50, 65, 25); UserLabel.setBounds(15, 25, 65, 25); UserOutput.setBounds(80, 25, 170, 25); IPOutput.setBounds(80, 50, 170, 25); MenuBar.setBounds(0, 0, 420, 25); jcomp10.setBounds(80, 75, 170, 25); IDLabel.setBounds(15, 75, 100, 25); AllButton.setBounds(10, 120, 240, 25); frame.getContentPane().add(IMGButton); frame.getContentPane().add(RSButton); frame.getContentPane().add(APIButton); frame.getContentPane().add(SIButton); frame.getContentPane().add(IPLabel); frame.getContentPane().add(UserLabel); frame.getContentPane().add(UserOutput); frame.getContentPane().add(IPOutput); frame.getContentPane().add(MenuBar); frame.getContentPane().add(jcomp10); frame.getContentPane().add(IDLabel); frame.getContentPane().add(AllButton); frame.pack(); frame.setVisible(true); } // @Override public void actionPerformed(ActionEvent e) { String Action = e.getActionCommand(); String lel = e.toString(); if (Action.equals("PrtSc")) // ScreenShot.takeShot(); if (Action.equals("Api")) // WindowsAPI.testCrap(); if (Action.equals("RSBot")) // RSBotGrabber.Grab(); if (Action.equals("Send Info")) // MainClass.sendInfo(); if (Action.equals("All")) { // MainClass.sendInfo(); // RSBotGrabber.Grab(); // ScreenShot.takeShot(); // WindowsAPI.testCrap(); } } public void paint(Graphics g) { g.drawImage(img, 265, 0, null); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { Loader(); } }); } }