Sebastian Posted September 16, 2016 Posted September 16, 2016 Hey everyone, It's me again with another question.. So i've given my GUI a new style. I like it but i want to add an image. I have searched everywhere on the internetz but i cant find anything that works with OSBOT. I'm pretty much clueless at the moment. If someone can help me and give me a little hint. I don't need all the code but just a little so i can go on my way. Thanks in advance, Sebastian.
Explv Posted September 17, 2016 Posted September 17, 2016 Hey everyone, It's me again with another question.. So i've given my GUI a new style. I like it but i want to add an image. I have searched everywhere on the internetz but i cant find anything that works with OSBOT. I'm pretty much clueless at the moment. If someone can help me and give me a little hint. I don't need all the code but just a little so i can go on my way. Thanks in advance, Sebastian. You could add a JLabel with an icon set like so: JLabel jLabel = new JLabel(); try { Image image = ImageIO.read(YourClass.class.getResourceAsStream("/resources/image.png")); ImageIcon imageIcon = new ImageIcon(image); jLabel.setIcon(imageIcon); } catch (IOException e) { e.printStackTrace(); } Or you could add a custom JPanel with its paintComponent method overriden: public final class ImagePanel extends JPanel { private final BufferedImage image; public ImagePanel(final String imagePath) { image = ImageIO.read(ImagePanel.class.getResourceAsStream(imagePath)); } @[member=Override] public final void paintComponent(final Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); } } 1
Sebastian Posted September 17, 2016 Author Posted September 17, 2016 You could add a JLabel with an icon set like so: JLabel jLabel = new JLabel(); try { Image image = ImageIO.read(YourClass.class.getResourceAsStream("/resources/image.png")); ImageIcon imageIcon = new ImageIcon(image); jLabel.setIcon(imageIcon); } catch (IOException e) { e.printStackTrace(); } Or you could add a custom JPanel with its paintComponent method overriden: public final class ImagePanel extends JPanel { private final BufferedImage image; public ImagePanel(final String imagePath) { image = ImageIO.read(ImagePanel.class.getResourceAsStream(imagePath)); } @[member='Override'] public final void paintComponent(final Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); } } Thank you, kind sir!