jpanel

JPanel not showing up

假装没事ソ 提交于 2019-12-02 15:24:49
问题 Why is the UI not showing up in my code below: public class GUI extends JPanel{ public GUI(String name, String address, List<String> reviews, Icon icon){ setSize(600,600); setLayout(new BorderLayout()); JLabel iconLabel = new JLabel(icon); JLabel nameLabel = new JLabel(name); JLabel addressLabel = new JLabel(address); JPanel southReviewPanel = new JPanel(); southReviewPanel.setLayout(new BoxLayout(southReviewPanel, BoxLayout.Y_AXIS)); for (String review: reviews) { southReviewPanel.add(new

How to add scrollbar to panel?

依然范特西╮ 提交于 2019-12-02 15:20:30
问题 I need help. I have one panel which can need to have width 1000px. I need to add lot of buttons with different size ( I add with flow layout and it works fine). Problem is that I have height on screen example 500px but when I add buttons panel has bigger size. How to add scrollbar to panel ? 回答1: Add your panel to scrollpane and add that pane where you are adding your panel instead of panel JScrollPane jScrollPane = new JScrollPane(panel); 来源: https://stackoverflow.com/questions/5790525/how

Repaint does not update the screen

主宰稳场 提交于 2019-12-02 14:48:01
问题 I would like to repaint my screen. As of now all it does is show the first screen with a dot where the head is supposed to be. This is fine, however I've written in my code that I want to move the head down 10 pixels every second. I'm printing at what point the head is supposed to be at, and in the command prompt it shows that the y value is indeed increasing. However on my screen the head is not moving. I have tried using the revalidate method, trying to extend the canvas class instead of

Adding a MouseListener to a panel

孤者浪人 提交于 2019-12-02 13:58:51
I am trying to add the mouse actions to my panel. This is what the program is supposed to do: Write a program that allows the user to specify a triangle with three mouse presses. After the first mouse press, draw a small dot. After the second mouse press, draw a line joining the first two points. After the third mouse press, draw the entire triangle. The fourth mouse press erases the old triangle and starts a new one. I would strongly recommend you start by having a read through How to Write a Mouse Listener . When ever you get stuck, these tutorials (and the JavaDocs) are the best place to

Switching between JPanels in a JFrame

只谈情不闲聊 提交于 2019-12-02 13:55:45
问题 Now I know there are many, many questions on this and I've read a dozen. But I've just hit a wall, I can't make heads or tails of it. Heres my question. I have 3 Panel classes. ConfigurePanel.java ConnectServerPanel.java RunServerPanel.java and my JFrame class StartUPGUI.java This is what is initialised at startup private void initComponents() { jPanel1 = new javax.swing.JPanel(); startUp = new sjdproject.GUI.ConfigurePanel(); runServer = new sjdproject.GUI.RunServerPanel(); serverConnect =

Switch two panels in on

筅森魡賤 提交于 2019-12-02 13:19:32
I have got one J Frame that includes 2 panels , I was able to switch between them using Visible but I want them to appear in the same position and the same size the other was in. Use a CardLayout to swap JPanels. The tutorial can be found here: CardLayout tutorial . When you do this, you will need a JPanel to be set to use the CardLayout and which will hold your other two JPanels. You will need to add these JPanels to the CardLayout using JPanel with String constants, so that the CardLayout will be able to identify the views with a String. For instance: CardLayout cardLayout = new CardLayout()

Panel losing color

给你一囗甜甜゛ 提交于 2019-12-02 12:59:28
When I click on the button that activates the file chooser, and add the resulting file the panel color disappears. Does anyone know why this is happening? import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JLabel; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.filechooser.FileSystemView; import javax.swing.JFileChooser; import javax.swing.plaf.FileChooserUI;

how to set the size of JPanel in java

。_饼干妹妹 提交于 2019-12-02 12:38:44
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? 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 and return a calculated Dimension that works best in all situations. For example: import java.awt.Color;

Can't draw to JPanel with getGraphics

强颜欢笑 提交于 2019-12-02 12:34:26
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 LaFrame. Here's the main class: package ElPackage; public class Resistores { public static void main

JFrame does not add component when JButton is pressed

故事扮演 提交于 2019-12-02 12:15:07
My code is basically about having a frame and it has a button. You press the button you can draw rectangles, getting coordinates from the mouse press and the mouse release. Now, if you remove the button the code works perfectly, here is the code. //testing file package ActionTest; import java.awt.*; import javax.swing.*; public class MouseTest { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new MouseFrame(); frame.setTitle("MouseTest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame