jpanel

Only one component shows up in JFrame

南楼画角 提交于 2019-11-26 00:49:08
问题 As an improvement to my encryption project I decided to make a little GUI. However, when I run the program, only the top element shows up on the screen and it appears to obscure the others, though I have no way of checking. Does anyone know why? Below is my code in its entirety besides e() and d() because those simply encrypt a string and have nothing to do with a GUI. I would also like a way to speed it up as much as possible without editing the encryption, just to make it as great as

How do I Switch JPanels inside a JFrame

风流意气都作罢 提交于 2019-11-26 00:44:50
问题 Quite green regarding javas component-stuff etc so please excuse me if information given by me isn\'t enough! Considet the code below. Adding menu and menu showing in frame, no problem. I want when gameOn() is called to remove the menu and instead start the game. The code below only makes the Frames surface \"blank\", no gamepanel added. Any thoughts/suggestions on how to fix it? The MenuPanel has a mouselistener. public class GameFrame extends JFrame { private MenuPanel mp; //extends JPanel

How do I change JPanel inside a JFrame on the fly?

泪湿孤枕 提交于 2019-11-26 00:38:13
问题 To put it simple, there\'s a simple java swing app that consists of JFrame with some components in it. One of the components is a JPanel that is meant to be replaced by another JPanel on user action. So, what\'s the correct way of doing such a thing? I\'ve tried panel = new CustomJPanelWithComponentsOnIt(); parentFrameJPanelBelongsTo.pack(); but this won\'t work. What would you suggest? 回答1: Your use case, seems perfect for CardLayout. In card layout you can add multiple panels in the same

Java: Difference between the setPreferredSize() and setSize() methods in components

那年仲夏 提交于 2019-11-26 00:16:43
问题 Ok, I read the Java Documentation and I just can\'t figure out what is the main difference between those two methods. Sometimes I used setSize(), sometimes setPreferredSize(), sometimes one does what I want, sometimes the other. So, what is the main difference between the two? Which one should I use for JFrames and JPanels ? Thanks 回答1: The short answer is: it's complicated. The slightly longer answer is: use setSize() if your component's parent has no layout manager, and setPreferredSize()

How to set a background picture in JPanel

旧巷老猫 提交于 2019-11-25 23:50:04
问题 hello i am using JPanel as my container of my frame then i really want to used a background picture in my Panel i really need help this is my code so far . this is the updates please check here is my code now import java.awt.*; import javax.swing.*; import java.awt.event.*; public class imagebut extends JFrame { public static void main(String args []) { imagebut w = new imagebut(); w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); w.setSize(300,300); w.setVisible(true); } public imagebut() {

JComponents not showing up with picture background?

╄→гoц情女王★ 提交于 2019-11-25 22:58:35
问题 My components are not showing up. How do I fix this? Code: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*; public class login implements ActionListener{ JTextField gusername; JTextField gpassword; static String username; static String password; void logini() throws IOException { JFrame window = new JFrame(\"Login\

How to add an image to a JPanel?

痴心易碎 提交于 2019-11-25 22:57:37
问题 I have a JPanel to which I\'d like to add JPEG and PNG images that I generate on the fly. All the examples I\'ve seen so far in the Swing Tutorials, specially in the Swing examples use ImageIcon s. I\'m generating these images as byte arrays, and they are usually larger than the common icon they use in the examples, at 640x480. Is there any (performance or other) problem in using the ImageIcon class to display an image that size in a JPanel? What\'s the usual way of doing it? How to add an

Program not accessing method paintComponent() of extended JPanel class

假如想象 提交于 2019-11-25 22:46:56
问题 This is the JFrame package client.connection; import java.awt.Dimension; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import javax.swing.JFrame; class DrawFrameRemoteControl extends JFrame { private DrawPanelRemoteControl imagePanel; private ClientRemoteControlConnection clientRemoteControlConnection; private ObjectInputStream clientInputStream; private ObjectOutputStream clientOutputStream; private Dimension imageDimension; private Dimension serverDimension; public

Draw a line in a JPanel with button click in Java

烂漫一生 提交于 2019-11-25 22:01:31
问题 I want to draw a line in a JPanel. This is my GUI and I want a line in the JPanel in white. I find many examples but the problem is the how to use it. In many exmples, always they draw in a JFrame that extends from a JPanel. I want to add the Panel to the Frame and add some buttons to draw lines in many directions and use the X button in center to clean the JPanel. This is the code of the interface: import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import

Java: maintaining aspect ratio of JPanel background image

£可爱£侵袭症+ 提交于 2019-11-25 21:42:30
问题 I have a JPanel with a painted background image and a layout manager holding other smaller images, all of this inside a JFrame . The background image is pretty big and I want to be able to have it maintain its aspect ratio whether its on a big or small monitor. Eventually, I want to be able to have my LayoutManager and the smaller images in its cells \"glued\" to the background picture. I looked around for resources and it seems that many examples use a BufferedImage but I am not; will this