jpanel

get JSlider's input and changes

偶尔善良 提交于 2019-12-02 19:25:21
问题 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

Navigating between multiple panels

孤者浪人 提交于 2019-12-02 19:08:07
问题 Can anyone tell me how to go about coding for navigation between multiple JPanel classes taking the event trigger from JButton from the objects (panels) themselves? I have read about CardLayout . The panel can be swapped from the events happening in the parent panel. What I want to achieve is on click of a button embedded in the panel, it should should disappear or a desired panel should be displayed. Can't seem to find a solution. 回答1: There is nothing about CardLayout that prevents

how to set the size of JPanel in java

浪尽此生 提交于 2019-12-02 19:00:09
问题 I have a JPanel in my java code and I want to set its size, I have used JPanel.setSize(500,500); and JPanel.setSize(new Dimension(500,500)); but both are not working. Please tell how I can set the size of JPanel? 回答1: Most Swing layout managers respect a component's preferredSize and not its size. You could call setPreferredSize(new Dimension(500, 500)) , but this can be overridden later in your code, and can lead to an inflexible GUI. Better to override the JPanel's getPreferredSize() method

Is this JPanel code good? Not showing the other JPanel when clicked on the button

ぐ巨炮叔叔 提交于 2019-12-02 18:59:26
问题 How to get that second JPanel to show when someone clicked on the button? The code is giving an error - unknown source. What am I missing? package Com.global; import java.awt.BorderLayout; public class Govinda extends JFrame { /** * */ private static final long serialVersionUID = 1L; private JPanel contentPane; private JPanel panel; private JPanel panel_1; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try

Calculator: Buttons ONLY show up when mouse hovers over them in Test JFrame class

扶醉桌前 提交于 2019-12-02 17:23:03
问题 I'm rushing, so idc about the duplicate. I'm still trying to learn Java and the terms, until the end of this semester, that is. I used a template. I'm using a background image ("panel"), which complicates everything. Basically, the buttons only show up when I hover over them. It has something to do w/ the JPanels, clearly. I excluded code that you'd probably ask for so that hopefully, someone helps me this time because my buttons are not like the ones I've seen when looking on other

How do I make my button display at the time I want it to?

ⅰ亾dé卋堺 提交于 2019-12-02 16:06:15
问题 I'm working on this game for my girlfriend and I've been stuck on the same problem for a few days now. Basically, I want her to be able to press the "Gather Wood" button 5 times then, right after she presses it the fifth time, the "Create Fire" button should pop up. 1.The problem is that no matter which way I attempt to program the method to show up on the fifth button press it just doesn't show up. I would appreciate any coding tips or anything y'all think I can do to clean up my current

Difference between JPanel, JFrame, JComponent, and JApplet

ぐ巨炮叔叔 提交于 2019-12-02 16:04:54
I'm making a physics simulator for fun and I was looking up graphics tutorials when I tried to figure out the difference between all these J's. Can somebody elaborate on them or perhaps provide a link to a helpful source? Those classes are common extension points for Java UI designs. First off, realize that they don't necessarily have much to do with each other directly, so trying to find a relationship between them might be counterproductive. JApplet - A base class that let's you write code that will run within the context of a browser, like for an interactive web page. This is cool and all

KeyListener not working with PaintComponent

允我心安 提交于 2019-12-02 15:58:57
问题 My program is supposed to wait for either the left or right arrow key to be pressed, then change a value so the next time PaintComponent is updated, the screen looks different. However, the screen doesn't change when I run the program. Here are the variable declarations: static KeyListener listen; public static int slide = 0; Here's the KeyListener declaration in the main: listen = new KeyListener() { public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_LEFT && slide>0)

Can't draw to JPanel with getGraphics

孤街醉人 提交于 2019-12-02 15:55:47
问题 I was wondering what went wrong. I've done this before but for some reason I can't get this to work this time. I designed the project in Netbeans. The most relevant part is the method initTiras, which is suppossed to draw something, but it doesn't. I included the code generated by NetBeans. Here's the most simplified version of the code, and still it paints nothing. So I created a new Frame in the proyect. Then I put a JPanel in it (in desing mode). The JPanel's called ElPanel and the JFrame

Refreshing picture in drawingPanel extends JPanel

巧了我就是萌 提交于 2019-12-02 15:39:16
问题 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