jpanel

Add GraphStream graph into my custom jPanel

纵饮孤独 提交于 2019-12-02 10:06:33
问题 I am working on GraphStream library. For now, When I run my program it opens new window for my graph and separate window for my graph. I tried to create a JFrame and add JPanel into JFrame , after all this I tried to add graph into my JPanel but it says that graph object is not a component. Here is my code: import java.awt.BorderLayout; import java.awt.EventQueue; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java

JPanel not showing up

ぃ、小莉子 提交于 2019-12-02 10:06:25
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 JTextArea(review)); } add(southReviewPanel); add(iconLabel, BorderLayout.WEST); JPanel northPane = new

Java drawing on JPanel which on a JFrame [closed]

♀尐吖头ヾ 提交于 2019-12-02 10:01:06
Hi I have a JFrame and there are two JPanels on top of it. My intention is to draw on the JPanels. Can anyone please share any Java code? All the JComponents ( of which JPanel inherits from ) have a paintComponent(Graphics g ) method that you can override. Basically... oh.. well, I think this would be more appropiate: http://java.sun.com/developer/technicalArticles/GUI/java2d/java2dpart1.html Naive sample: Source code: import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class X { public static void main( String [] args ) { JFrame frame = new JFrame(); frame.add( new JPanel(

Java Swing: JPanel only adds components when JFrame window is maximized or it's size changed

匆匆过客 提交于 2019-12-02 09:40:40
I have a Java program that creates a JFrame, a JPanel, and several JTextAreas. I set the text of the JTextAreas and then add them to the JPanel. When the program loads, I only see the empty JFrame. However, if I maximize, or change the size of the program window, the JTextAreas, and their respective texts appear on the screen. How can I correct this so that the program loads, with the text areas populated, without the need to mess with the window? My apologies in advance for being a Swing noob. My guess: You need to call setVisible(true) on the JFrame after adding all components to it. Next

JLabel only shows if initComponents() is deleted

你。 提交于 2019-12-02 09:35:36
MainFrame.java -JFrame public MainFrame() { initComponents(); Letters pl = new Letters(this); this.setContentPane(pl); this.setTitle("Preset Lessons"); this.pack(); } Letters.java -JPanel public Letters(JFrame frame) { initComponents(); JLabel label = new JLabel(); label.setText("Sample"); this.add(label); } if initComponents() in Letters.java is deleted thats the only time the JLabel will show up. How can I put the new JLabel to my existing JPanel? Contents of Letters.java's initComponents(); if I removed the iniComponents in the constructor it will create the JLabel. private void

Adding JScrollPane to a JPanel without a Layout Manager

泪湿孤枕 提交于 2019-12-02 09:21:09
问题 Before I start, I'm aware that its a bad idea to not use a Layout Manager and usually I do use one, however, I also have all my components automatically re-size and relocate based on the size of the window. In addition the program I'm working on is only intended to run on 1 machine throughout its entire lifetime. Please don't downvote me just because of lack of layout manager, I found it to be what I need for this particular program. To my issue, I found a similar post on stackoverflow but a

paintComponent is not being called in JPanel

和自甴很熟 提交于 2019-12-02 09:19:30
I have following code: package hra; import java.awt.Color; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import static javax.swing.JFrame.EXIT_ON_CLOSE; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class HerniPole extends JPanel implements KeyListener { public int velikostPole; HerniPole(int velikostPole) { this.velikostPole = velikostPole; Color background = new Color(187, 173, 163); EventQueue.invokeLater(new Runnable() {

Click Event - Accessing a boolean variable from another class [closed]

你。 提交于 2019-12-02 08:56:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . Stuck on a problem that requires grabbing a boolean variable from another class. I have the following for-loop , boolea n and if-else statements import java.awt.*; import javax.swing.*; import java.awt.Color.*; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.util.Random;

Using an image for the background of a JPanel and JButton

拜拜、爱过 提交于 2019-12-02 08:37:00
I am trying to use an image I made in photoshop as the background for my GUI. How do I do that? also I made some images I want to display in the button backgrounds after the action is performed... For the JButton, use this: JButton button = new JButton("Button Name", new ImageIcon("foo.png"); The Panel is a bit more interesting. This is a good method, though: ImagePanel panel = new ImagePanel(new ImageIcon("foo.png").getImage()); 来源: https://stackoverflow.com/questions/8373006/using-an-image-for-the-background-of-a-jpanel-and-jbutton

How to highlight (uniform visually select, draw transparent overlay) JPanel?

試著忘記壹切 提交于 2019-12-02 08:33:37
问题 Many custom Swing components are made of JPanel . Sometimes these components are required to be selectable. How is it possible to make JPanel look selected? It should be selected like other items do, like menu items, or JTable cells. I.e. entire JPanel should be covered with transparent blue. It would be excellent, if this would made exactly like other items in L&F / theme, Is it possible? 回答1: You could consider taking a look at JXLayer / JLayer , which would allow you to paint an overlay on