jpanel

JPanel doesn't repaint if repaint() is called within JFrame code

瘦欲@ 提交于 2019-12-01 21:33:54
问题 I have a class Forest and CellularJPanel , which extends JPanel and displays Forest . I wrote a primitive code to create JFrame , Forest , CellularJPanel and add CellularJPanel to the JFrame . Next is an infinite loop, which makes Forest update and CellularJPanel repaint. JFrame jFrame = new JFrame(); Forest forest = new Forest(); CellularJPanel forestJPanel = new CellularJPanel(forest); jFrame.add(forestJPanel); jFrame.pack(); //jFrame.setResizable(false); jFrame.setLocationRelativeTo(null);

Swing component setSize()/setBounds() issue

丶灬走出姿态 提交于 2019-12-01 20:45:27
Contents Overview Example Code Screenshots of Problem 1. Overview of problem So I'm writing a GUI for a complicated program I'm developing, and I get tired of trying to get components to scale correctly when the window is resized. At first I was using several layouts inside the jframe, and each jpanel to try and place the components correctly and scale them appropriately. Naturally, I got fed up with them, and I started trying to scale and set the x,y positions of the components dynamically (it's so much easier :D). Basically I'm trying to divide the screen into three sections left margin

JPanel with background image, with other panels overlayed

♀尐吖头ヾ 提交于 2019-12-01 20:31:08
I want to have a JPanel which uses an image as a background, with this I want to add new panels to this panels so that they sit on top of this background image. I have tried the following: Image background; public Table(){ super(); ImageIcon ii = new ImageIcon(this.getClass().getResource("pokerTable.png")); background = ii.getImage(); setSize(Constants.FRAME_WIDTH, Constants.TABLE_HEIGHT); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (background != null){ g.drawImage(background, 0,0,this.getWidth(),this.getHeight(),this); } JButton button = new JButton(

Resizing a JPanel inside a JFrame

本秂侑毒 提交于 2019-12-01 20:22:38
I am new to Java, started learning swing and have a problem with resizing a JPanel inside a JFrame. I am following this tutorial: http://vincentramdhanie.blogspot.com/2009/11/cardlayout-with-netbeans.html because ultimately I am learning each of the different layouts and have come to the CardLayout now. In the above, there is a JPanel being used for a status panel. That is what I want to do as well, but when I drag a JPanel onto my blank JForm it takes up all the space and I don't see any resizing handles for it like I would if I were using a .NET panel. Changing preferredSize in the

Window frame covering graphics content

三世轮回 提交于 2019-12-01 20:21:46
this is my first post here and I have a question that seems really nooby, but this has been troubling me for the past hour or so. I'm making a simple JFrame with a JPanel in it, but the Windows 7 border frame appears to be blocking my view of parts of the panel. For instance, if I draw a little square at coordinate 0,0, it will not appear and I suspect it's behind the window frame. I've tried messing around with pack, setsize, setpreferred size, setresizable, and different layouts, but I can't get it to show the top 20 pixels or so! This is what I have: public RedSunGame() { super("Red Sun");

how to put two jpanels side by side

别说谁变了你拦得住时间么 提交于 2019-12-01 19:36:37
I try to put two jpanels side by side, but in this moment i can not do what i want I have this code, this.videoPanel= new JPanel(); this.videoPanel.setBackground(new Color(102, 102, 102)); this.videoPanel.setPreferredSize(new Dimension(320, 240)); this.videoPanel.setLayout(new BoxLayout(this.videoPanel, 1)); GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createSequentialGroup() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(this.videoPanel, 10, 400, 500))); layout.setVerticalGroup(

How to repaint a jpanel every x seconds?

旧街凉风 提交于 2019-12-01 19:03:15
i would like to know how to repaint and update the background of a JPanel every x seconds...This is my code: package view; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class GamePanel extends JPanel { /** * */ private static final long serialVersionUID = 1L; private final JLabel score; private final static String[] BACKGROUND_COLORS = {"black", "blue", "darkpurple", "purple"};

Update content of JPanel on a frame on button click in another frame

五迷三道 提交于 2019-12-01 18:58:43
问题 I have created a frame x1 which has a panel p1. When x1 is loaded, checkboxes are added dynamically to p1. The number of checkboxes added to p1 depend on the number of data values in the database table(t1) that satisfy a particular criteria. There is a button b1 on frame x1. When b1 is clicked,it displays another frame x2 in which data values of the database table t1 can be modified. A button 'update' in x2,updates t1 to reflect the changes made to its data values. After modification,when x2

Update content of JPanel on a frame on button click in another frame

。_饼干妹妹 提交于 2019-12-01 18:46:40
I have created a frame x1 which has a panel p1. When x1 is loaded, checkboxes are added dynamically to p1. The number of checkboxes added to p1 depend on the number of data values in the database table(t1) that satisfy a particular criteria. There is a button b1 on frame x1. When b1 is clicked,it displays another frame x2 in which data values of the database table t1 can be modified. A button 'update' in x2,updates t1 to reflect the changes made to its data values. After modification,when x2 is closed I want the panel p1 in frame x1 to be updated automatically to reflect the changes made to

MouseEvent on JPanel - wrong coordinate

不打扰是莪最后的温柔 提交于 2019-12-01 18:46:28
I have written the following micro-paintbrush program in Java: import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.GridLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; class AuxClass1 extends JFrame implements MouseListener, MouseMotionListener{ private JPanel panel1 = new JPanel(); private JPanel panel2 =