jpanel

How to stop the auto-repaint() when I resize the Jframe

China☆狼群 提交于 2019-12-02 08:22:43
I am still learning Java, if someone can help me I will be very happy! Sorry for bad english, I am spanish! I am making a tile game, the game uses the classic "game loop" that cap the engine at 60fps The loop sleep and then call repaint(); This works fine! But.. The problem is that repaint event is called when the JFrame is resized or maximized! For example when the JFrame is maximized/resized the game render at 10000fps but when they dont, the game render at the speed I set, so there is a way to disable Automatic repaint and make it work ONLY when the "component.repaint()" is called from my

paintComponent not painting onto JPanel

一曲冷凌霜 提交于 2019-12-02 08:20:45
I am working on a homework assignment where I am supposed to make a program that allows you to paint custom shapes and lines, and move them around the screen. Originally I was using public void paint(g) to paint, but the shapes were flickering when I called repaint. Because of that I switched over to paintComponent(g) . However When I try to paint a shape nothing shows up. I believe this is because it isn't painting on top of the JPanel . The frame has 3 panels in a 3 row BorderLayout . [Button JPanel] [Draw Box JPanel] [Coordinate Jpanel] The panel I would like to draw on is the Draw Box

Java GridBagConstraints gridx and gridy not working?

落爺英雄遲暮 提交于 2019-12-02 08:11:03
问题 I am trying to use the gridx and gridy constraints to position my button. But they do not work! If I change the gridx and gridy variables, nothing happens. If I change the fill to GridBagConstraints to NONE , it still does not work. Am I missing something here? import java.awt.*; import javax.swing.*; public class Window extends JFrame{ private static final long serialVersionUID = 1L; JFrame frame = new JFrame("GUI"); JTextField username = new JTextField(20); public void CreateWindow(){

get JSlider's input and changes

岁酱吖の 提交于 2019-12-02 07:40:39
I need to use JSlider with getting input live, meaning that it will return an input without pressing any button. I have this piece of code for the slider: JPanel panel = new JPanel(); JSlider js = new JSlider(JSlider.VERTICAL, 0, 20, 10); js.setMajorTickSpacing(2); js.setPaintTicks(true); Hashtable labelTable = new Hashtable(); labelTable.put(new Integer(js.getMinimum()), new JLabel("x0")); labelTable.put(new Integer((js.getMinimum() + js.getMaximum()) / 2), new JLabel("x1")); labelTable.put(new Integer(js.getMaximum()), new JLabel("x2")); js.setLabelTable(labelTable); js.setPaintLabels(true);

Second row of gridbaglayout scrolling out of container

二次信任 提交于 2019-12-02 07:34:10
I am trying to achieve a layout similar to that of a carousel. It needs to have images added horizontally with a checkbox field in the second row. I have a panel within a jscrollpane and individual images are added to the panel as labels. Please see screen shot. screenshot When I scroll the pane , the first row containing the images stays well within the panel..but if you notice the second row of checkboxes , it scrolls out of the panel. Here is the code ... JLabel lab1=new JLabel(); for (int ii=0; ii<imageFiles.length; ii++) { GridBagConstraints constraint = new GridBagConstraints(); lab1 =

Refreshing picture in drawingPanel extends JPanel

浪尽此生 提交于 2019-12-02 07:23:55
I have to load a small icon on the botton of my software. just to have a loading/ok/error icon. as sudgested on "http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter06/images.html" i create a dwowing panel extending JPanel. class drawingPanel extends JPanel { Image img; drawingPanel (Image img){ this.img = img; } public void paintComponent (Graphics g) { super.paintComponent (g); // Use the image width & height to find the starting point int imgX = getSize ().width/2 - img.getWidth (this); int imgY = getSize ().height/2 - img.getHeight (this); //Draw image centered in the

I am trying to add a JButton array that I added to a panel onto my JFrame, yet nothing is showing up

邮差的信 提交于 2019-12-02 07:22:25
问题 Here is my code: For some reason nothing will appear on my screen, yet I don't know why, I believe I am initializing it correctly and adding it. Help? import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class main implements MouseListener{ final int WIDTH = 800, HEIGHT = 500, BOARD_WIDTH = 10, BOARD_HEIGHT = 10; private JButton [

Not able to add 3 JPanels to a main panel

╄→尐↘猪︶ㄣ 提交于 2019-12-02 07:11:45
I have 3 JPanels and I want to place them all in one JPanel. I used the GridBagLayout for the main panel. But only one panel is getting added. Why might this be? gblayout=new GridBagLayout(); gbc=new GridBagConstraints(); panel1Customizer(); panel2customizer(); panel3Customizer(); setLayout(gblayout); gbc.fill=GridBagConstraints.HORIZONTAL; gbc.anchor=GridBagConstraints.NORTHWEST; gbc.weightx=1; gbc.weighty=1; gbc.gridheight=GridBagConstraints.REMAINDER; add(panel1, gbc); add(panel2, gbc); gbc.gridwidth=GridBagConstraints.REMAINDER; add(panel3, gbc); The customizer methods are ones which add

How to get JScrollPanes within a JScrollPane to follow parent's resizing

南笙酒味 提交于 2019-12-02 07:11:08
So I have a bunch of JTable s. Each JTable is inside a JScrollPane . I'm then adding each of these JScrollPane s to a JPanel . I'm then adding this JPanel to a JScrollPane then that to another JPanel with BorderLayout . The larger JScrollPane properly resizes with its parent, but each of the smaller JScrollPane s have constant height, which is larger than the window when it is small. How can I get each of the children JScrollPane s to resize with the height of the window/their parent? I've tried adding more intermediary JPanel s with FlowLayout , BorderLayout , and nothing seems to work. Here

Modifying independent JPanels from the JFrame

久未见 提交于 2019-12-02 07:03:52
I've got a JFrame with two separate JPanels. One of the JPanels is filled with JButtons while the other has a couple of text fields. I added mouse listeners to the buttons via the JFrame and I want to make it so that when an event is fired from the first JPanel, the text fields in the second JPanel are changed. The two panels have their own classes. How would I go about doing this? Hovercraft Full Of Eels Use MVC, Model-View-Control, separation of concerns. Have the Control, which holds your listeners, change the state of the model. The Views -- your GUI's, have listeners added to them by the