jframe

JPanel taking up the whole JFrame

可紊 提交于 2019-12-13 00:56:11
问题 I have an issue where when I include the JPanel in my JFrame, it covers the entire screen. My code reads import java.awt.*; import javax.swing.*; public class TestFrameExample extends JPanel { static String TheQuestion; static String QN1 = "Question 1: "; static String Q1 = "What is Lead's chemical symbol?"; static String brk = "___________________"; public void paintComponent(Graphics g) { super.paintComponent(g); this.setBackground(new Color(135, 206, 250)); g.setFont(new Font("Tahoma",

Close one JFrame before opening another JFrame

萝らか妹 提交于 2019-12-13 00:43:39
问题 I want to close completely one JFrame before opening another . Consider the code : import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.InetAddress; import javax.swing.*; import javax.swing.border.EmptyBorder; /** * * @author X * */ class ServerConnect extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private JTextField m_serverIP; private JTextField m_serverPort; // you can use also

adding multiple components to Jframe.getcontentpane()

北城以北 提交于 2019-12-13 00:42:59
问题 I have a class that extends JPanel and draws a triangle. I called it from other class to create three triangles but when third triangle is drawn the previous two disappeared. How can I add multiple triangles that are shown together. Code is as follows: Triangle.Java: public class Triangle extends JPanel{ Point p1, p2, p3; public Triangle(Point _p1, Point _p2, Point _p3) { this.p1=_p1; this.p2=_p2; this.p3=_p3; } public void paint(Graphics g) { super.paint(g); int[] xs = {p1.x,p2.x,p3.x}; int[

Making a keyevent in a JFrame

∥☆過路亽.° 提交于 2019-12-13 00:41:02
问题 I'm trying to make a key make something happen in a JFrame. Right now I'm just trying to disable a button when you press the left key, but nothing is happening. I thought I have everything right, but it does nothing. EDIT: I noticed that when I don't click start first, it works. But after you press start, it won't respond. Here's my code so far: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MyFrame extends JFrame implements ActionListener, KeyListener {

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

How to resize window in Java from a click (in this case, a button)?

二次信任 提交于 2019-12-12 21:34:38
问题 I was just wondering how (and if) this is possible. I read somewhere about an ActionEvent with resize window(int, int) but I wasn't sure if that was an appropriate way to handle it. Edit: sorry this is in an GUI interface set up by JPanel 回答1: public static void main(String[] args) { final JFrame frame = new JFrame(); JPanel panel = new JPanel(); JButton button = new JButton("Click Me"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setSize

Dynamically updating markers in JMapViewer

ε祈祈猫儿з 提交于 2019-12-12 21:23:17
问题 Hello Stack Overflow community, I am a Java newbie and I am doing a simple java project where I take coordinates (lat and lon) from a (dynamic) source and use JMapViewer (Yes, not JXMapViewer) to display the markers on a map. I have put all the coordinates in two ArrayList(s). It looks like that: for(int i = 0; i < latArrayList.size(); i++){ map.addMapMarker(new MapMarkerDot((double)latArrayList.get(i), (double)longArrayList.get(i))); } EDIT: map is a jMapViewer object. And it works pretty

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

How to set window always on top of any other applications

﹥>﹥吖頭↗ 提交于 2019-12-12 18:35:50
问题 I have a JFrame which needs to be always on top of the other application. For this I am using setAlwaysOnTop() method of Window class. Here is my code : class Test1 extends JFrame { public Test1() { initComponents(); setTitle("Top Window"); setAlwaysOnTop(true); } private void initComponents() { jLabel1 = new JLabel(); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jLabel1.setHorizontalAlignment(SwingConstants.CENTER); jLabel1.setText("I am a top most window"); getContentPane().add

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