How to load an image into a JPanel using Java

So can’t comment(need 50 rep) but your file path is completely wrong you need it to be something like this new File(“C:/Users/”Insert Username”/Desktop/workspace/Java/BSC_Project/Application/src/resources/background.jpg”) except I’m not on your computer so you need to figure out your own file path, This would be assuming your workspace folder is on your Desktop which it almost certainly isn’t, … Read more

JTextArea content is not printing in printer fully [closed]

Many Swing components support printing out of the box You could use something as simple as JTextArea.print to get started, for example import java.awt.BorderLayout; import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Paper; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.io.File; import java.io.IOException; import java.util.StringJoiner; import … Read more

JButton size larger than specified

You’re not using a LayoutManager of any kind. The JButton will try to inherit the size of the parent container, as the default for a JFrame is BorderLayout (specifically, BorderLayout.CENTER). You could try using button.setPreferredSize(x, y); However I don’t think this would be enough by itself. Call getContentPane on the Jframe, and set a layout … Read more

Can this be made in Java? [closed]

Sounds like you need a Swing TabbedPane With the JTabbedPane class, you can have several components, such as panels, share the same space. The user chooses which component to view by selecting the tab corresponding to the desired component. If you want similar functionality without the tab interface, you can use a card layout instead … Read more