jpanel

how to use setLocation to move componets

丶灬走出姿态 提交于 2019-12-11 06:34:07
问题 I'm trying to set the components of this application to a set location using setLocation so far i haven't been able to move the components. There is more code but its get calling and setting this code for the most part. any ideas? import javax.swing.*; public class HangmanPanel extends JPanel { private static final long serialVersionUID = -5793357804828609325L; public HangmanPanel(){ JLabel heading = new JLabel("Welcome to the Hangman App"); JButton Button = new JButton("Ok"); //Button

Java JTabbedPane questions

南笙酒味 提交于 2019-12-11 06:13:07
问题 I'm using a JTabbedPane to hold each step in the wizard that I am building. Navigation between steps is doing using the Previous/Next buttons or by selecting a tab. The buttons decrement/increment the JTabbedPane's SelectedIndex. I need to validate each step before proceeding to the next step. Essentially, I'm having difficulty determining which event to use. The StateChange event occurs too late. Which event do I need to observe? Another irritation: when the wizard runs, it seems to save the

Adding a JLabel to a Panel - how to layout the components properly?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 05:53:14
问题 I want to put some words in the frame so I used panel1.add(new JLabel("Hello")); But there are some buttons which their sizes and positions are customized. I heard that we have to setLayout(null) for the button customizing and this is also making the label not showing up. (Not sure if it is because of this) What is the solution for this? 回答1: I'll point you to the Java tutorials for laying out components - they give a good introduction to Swing formatting and layouts. Rather than calling

How to draw a triangle with border with Java Graphics

不想你离开。 提交于 2019-12-11 05:50:00
问题 I'm trying to draw a triangle with a border using the Graphics.drawPolygon() method The triangle is properly drawn, but how can I calculate the 3 points of the border? I already did it with a circle, but I can't seem to find a solution for triangle. A requirement of the instructor as that it cannot use Graphics2D . My code: if (xPoints != null && yPoints != null) { int[] nXPoints = new int[] { xPoints[0] - borderThickness, xPoints[1] - borderThickness, xPoints[2] - borderThickness }; int[]

JPanel states for Synth

非 Y 不嫁゛ 提交于 2019-12-11 05:36:58
问题 In my application I have some custom buttons which have custom text/icon layouts and some extra elements not normally associated with buttons. e.g. Some have 2 text labels instead of one. I've implemented my custom buttons as follows: class CustomButton extends JPanel implements MouseListener { CustomButton() { setName("CustomButton"); } } I'm using Synth for the L&F, and I would like to have as much of the style information as possible (primarily color settings) defined in the XML file). In

JScrollPane & Graphics2D

痴心易碎 提交于 2019-12-11 05:17:30
问题 I am trying to draw graphics that is bigger than the JFrame and use JScrollPane to scroll the entire graphics. I created a simple example with two lines. The scroll bars appear but the graphics do not show. import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; public class Test extends JPanel{ public static void main(String... args) { Test test = new Test(); JFrame frame = new

Keyboard not inputing anything java

爱⌒轻易说出口 提交于 2019-12-11 04:56:20
问题 i have been trying this code and editing it but it doesnt work. it is suppose to get a keyboard input store it in the variable "c" and then compare that to keys on the keyboard. Then it is suppose to move a little square depending the key pressed. The keyboard doesnt seem to be recognised. Can someone please help me? Please be aware i am 14 so please dont say how simple and easy it is, i am still learning and could you also write it in a way i am likely to understand. Thank you in advance

Why does a JButton not show unless text is set after JButton is added to JPanel?

▼魔方 西西 提交于 2019-12-11 04:33:01
问题 I have a problem with my JButton objects behaving in an odd way: JFrame frame = new JFrame(); frame.setSize(new Dimension(200, 200)); frame.setVisible(true); //Constraints GridBagConstraints constraints = new GridBagConstraints(); constraints.weightx = 1.0; constraints.weighty = 1.0; ... // JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); JButton button = new JButton("Categories:"); panel.add(button, constraints); frame.add(panel); This results in the following GUI: Where is

Java MVC - how to change view - JPanel

送分小仙女□ 提交于 2019-12-11 04:14:26
问题 I am creating to learn MVC in Java. I read that Java app with few JFrames is bad idea and better solution is to use JPanel. JDialog also does not solve the problem, because then I have too many of them. I have the MainFrame with a few buttons and my question is - how to change JPanels on the Frame after click on one these buttons? I know how to change view if the View is Frame... //ActionListener in the MainController public void actionPerformed(ActionEvent e) { TheView theView2 = new TheView

JScrollPane problem

允我心安 提交于 2019-12-11 03:54:46
问题 i have a jscrollpane added to jtabbedpane and inside the jscrollbar pane i have a jpanel. In the jpanel i have few buttons which i am creating on runtime. My idea is it get a scroll bar when the button size that i am adding dynamically during runtime grows. I cant get that to happen. The button size is increased and it hides when the size goes beyond the jpanel's view. I am increasing the size of jpanel and the buttons inside it using setSize(). I have also used jScrollPane2.setViewportView