Hello, this is my JPanel with image on it
Why does the GUI mess up?
the buttons and labels are gone![]()
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello, this is my JPanel with image on it
Why does the GUI mess up?
the buttons and labels are gone![]()
Morning Koâk,
Please post your code for us to look at![]()
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputationby clicking the
button on their useful posts.
Looking for a Java job? Visit - Java Programming Careers
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:
frame.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel"); } catch (Exception e) { System.out.println("Failed to load Raven Graphite skin"); }
and
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.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputationby clicking the
button on their useful posts.
Looking for a Java job? Visit - Java Programming Careers
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![]()
Last edited by Koâk; May 12th, 2009 at 10:55 AM.
Hello Koâk,
I have had a play around with the code. Check this out:
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(); } }); } }
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputationby clicking the
button on their useful posts.
Looking for a Java job? Visit - Java Programming Careers