jpanel

Draw Line in a JLabel and add as JPanel in a JFrame does not function

青春壹個敷衍的年華 提交于 2019-12-13 00:38:24
问题 im very new in Java so sorry for any stupid question. Here is my problem: I just want to draw a line - if I add the JLabel Myline() directly as label to the JFrame MyFrame , then it will be showing in the resulting JFrame -Dialogwindow, but if I add MyLine() to the JPanel panel and panel to MyFrame then there is no Line. Why? package examples; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.GridBagLayout; import java.awt

change TitledBorder color dynamically in java

戏子无情 提交于 2019-12-13 00:23:39
问题 I have created a TitledBorder and set it to a JPanel. JPanel panel = new JPanel(); panel.setBorder(javax.swing.BorderFactory. createTitledBorder(null, "title", javax.swing.border. TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border. TitledBorder.DEFAULT_POSITION, null, java.awt.Color.red)); now I want to change the color of the title text of the border; and if possible border lines. I see when I change color of the border by the method titledborder.setTitleColor(theColor); and revalidate()

Closing JFrame with Button

ⅰ亾dé卋堺 提交于 2019-12-12 22:24:55
问题 I am currently using Eclipse's drag and Drop feature, I have one application window which comes with JFrame by default and is able to setVisible(false); but my other frames/panel/window I have created with JPanel and with extending JFrame. Because of extend I am unable to setVisible(false or true); it has no effect at all on the window it still remains true. My code : private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater

Repainting JPanel after button click

Deadly 提交于 2019-12-12 21:31:37
问题 I'm new in Java Swing and I have a strange problem to refresh my JPanel . I create a static JPanel componant in my frame and I call a static method from a FileListenner to repaint my JPanel public static void repaintPlan(JPanel f) { f.paint(f.getGraphics()); f.revalidate(); // or validate } I mean, when I detect change in file content, I calculate the new coordinates and I repaint the JPanel (I create a class exends from JPanel to define paintComponent()` method) Everything is working fine

Adding the same components to multiple panels? [duplicate]

♀尐吖头ヾ 提交于 2019-12-12 20:43:28
问题 This question already has answers here : Can't a Swing component be added to multiple containers? (4 answers) Closed 3 years ago . I'm using Swing and I am trying to add the same components to multiple panels. However, only the panel I add to the frame last has these buttons. I am adding the same set of labels/textfields to p2, p3, and p4. But since I added the labels/textfields to p4 last, it seems to show only p4 as having it. How can I re-use these components for multiple JPanels so I don

Java Swing Add JPanel to JPanel

梦想与她 提交于 2019-12-12 20:25:25
问题 The Situation I am currently trying to build a 2D game with Java's Swing. For this, I have my main class Puzzle which is subclassing JFrame . To my frame I add my main JPanel which consists of several JPanel s added together (each of them being a new piece). EDIT 2: PlayingField is my model which will store the current location of each piece. One can select a piece with the mouse (the plan is to highlight it) and move it with the arrow keys as long as the next step (a full cell, so approx.

Graphics on top of a Panel

百般思念 提交于 2019-12-12 19:21:42
问题 I am having trouble with the Graphics that I am drawing on a Panel which has a JLabel on top of it. I am using a custom paintComponent(Graphics g) method to draw a String on the Panel. I want the string to show on top of the JLabel instead of under the JLabel, which is what is currently happening. Here is the paintComponent method if you want to see it: public void paintComponent(Graphics g){ super.paintComponent(g); if(a.shouldAnnotate()){ FontMetrics size= g.getFontMetrics(); if(getWidth()>

How do I add a bunch of JPanels to my JFrame using Java Swing?

狂风中的少年 提交于 2019-12-12 18:16:50
问题 I generate a bunch of JPanels and then pass them into a class that extends JFrame. How do I add an indefinite number of JPanels to this JFrame. I was also reading about JScrollPane should I incorporate this somehow into the design? Example Code: class foo extends JPanel { //generate JPanels } class bar extends JFrame { //grab some amount of foo classes and put them into this JFrame and show it } Also is there anything I need to watch out for when showing this JFrame? Thanks 回答1: How do I add

Zoom in and out of jPanel

别来无恙 提交于 2019-12-12 18:13:10
问题 I am wondering what is the best way to retrieve the location of a mouse clic after a zoom was made using paintComponent of a panel? (The location relative to this zoom). Here's the zoom code : public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if(zoomer==true){ at.scale(zoom,zoom);//at = AffineTransform... zoomer=false; } g2.transform(at); In my main class, I use a mouse listener private class and override the mouseRelase method : @Override

Display java JPanel in a JFrame

笑着哭i 提交于 2019-12-12 17:23:13
问题 I'm having problems getting my JPanel to display properly. I want to use different extended JPanels to display what I want the user to do with this program (which is ultimately to display photographs). Below is the code for the only two classes that exist at this point. Unfortunately, I'm having problems just getting this to work right out of the gate with the first panel which was to present the user with the ability to select different graphic images. What's happening is, I can't get my