jframe

How do I arrange JPanels from top to bottom?

十年热恋 提交于 2019-12-25 04:05:20
问题 I'm currently self-studying Java. I'm learning Graphical User Interface(GUI) programming. I want JPanel s to be arranged from top to bottom in a JFrame .First of all,I have a JLabel added to the first JPanel . The second JPanel has 5 JRadioButtions . The third JPanel has a JButton and a JLabel . When the JButton is pressed,the JLabel in the 3 rd JPanel shows some text. I used BoxLayout ( BoxLayout.X_AXIS ) for all the JPanels and added all 3 of them into a JFrame which has FlowLayout() . Here

GUI, JComboBox and opening a new window

与世无争的帅哥 提交于 2019-12-25 03:50:35
问题 I am new to Java and especially new to GUI and it's super confusing to me right now. I'm making a program for class that is supposed to have a menu (JComboBox I'm assuming) that opens a new window when an option is selected. I am just working on the first option where you click "The Matrix" and a new window pops up with two buttons called "Red Pill" & "Blue Pill" and thats where I've hit a wall. I got to the point where I am able to create a new window (not sure if this is even the right

Jframe. Cant get multiple components to display

孤人 提交于 2019-12-25 02:43:20
问题 I am having trouble getting two different components to display at the same time. public class BandViewer { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(1000, 800); frame.setTitle("band"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); BandComponent component = new BandComponent(); ConcertBackground component1 = new ConcertBackground(); frame.add(component); frame.add(component1); frame.setVisible(true); } } Now I read on this forum that you can

My JFrame is not changing when key pressed

坚强是说给别人听的谎言 提交于 2019-12-25 02:33:19
问题 I have a Jframe set on a timer and im trying to change one of the pictures by pressing the down key (special code 40), yet nothing is happening. import javax.swing.JFrame; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*; import java.awt.image.BufferedImage; public class MenuScreen extends JFrame { private static JFrame frame; GameKeyboard GK; boolean gamePlay = false; boolean gameQuit = false; boolean gameTwoPlayer = false;

Two buttons (with a fixed width/height and fixed position) with JFrame

早过忘川 提交于 2019-12-25 02:16:50
问题 I want to preface that yes, this is a homework question. We are told to create two buttons that increment their own individual counters. The counter part is done in another class not shown here. I first create a new JFrame and two buttons with their own text. JFrame frame = new JFrame(); JButton button1 = new JButton("Click me!"); JButton button2 = new JButton("Click me too!"); I set their bounds. button1.setBounds(0, 0, 100, 50); button2.setBounds(0, 50, 100, 50); Adding these buttons onto

Should I use JFrame or JDialog?

浪子不回头ぞ 提交于 2019-12-25 02:03:13
问题 In my GUI, by clicking on the button "Help", I want to open a new window within it containing som text information stored in HTML via JEditorPane . My question is: Should I store an instance of JEditorPane object within JDialog or JFrame? What kind of pros/cons both components can offer? I do not want to make any operations within this window, it will just serve to show the text information. 回答1: The differences between JDialog and JFrame are, that JDialog has no maximize/minimize button, and

How to get JPanel equal width and height

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 01:58:00
问题 I found the following code from http://www.java-forums.org/new-java/7995-how-plot-graph-java-given-samples.html. I don't understand why w = getWidth() and h = getHeight() are not equal. And how to make them equal to each other? Thanks import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class GraphingData extends JPanel { int[] data = { 21, 14, 18, 03, 86, 88, 74, 87, 54, 77, 61, 55, 48, 60, 49, 36, 38, 27, 20, 18 }; final int PAD = 20; protected void paintComponent

How to make JFrame paint only after I click button?

 ̄綄美尐妖づ 提交于 2019-12-25 01:51:30
问题 When I run the application the whole frame is painted black. How can I make it so that it starts out clear then it gets painted when I press the button? package card; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class BdayCard extends JFrame { JButton button1, button2; JPanel panel; BdayCard() { panel = new JPanel(); button1 = new JButton(); button1

How to add scrollbar in JFrame with null layout?

北城以北 提交于 2019-12-25 01:46:44
问题 I want to add a vertical scroll-bar on my JFrame with null layout. Is it possible or not? please help! 回答1: Just set the JScrollPane as ContentPane for JFrame as it is described here: public class TabbedPaneTest { public static void main(String [] a) { final JFrame frame = new JFrame(); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane pane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); frame

How can I change the JPanel from another Class?

﹥>﹥吖頭↗ 提交于 2019-12-25 01:45:13
问题 Hi, I'm new to Java and I have the following problem: I created a JFrame and I want the JPanel to change when clicking a JButton. That does almost work.The only problem is that the program creates a new window and then there are two windows. One with the first JPanel and one with the second JPanel. Here is my current code: first class: public class Program { public static void main (String [] args) { new window(new panel1()); } } second class: import java.awt.Toolkit; import javax.swing