Guys, Im wondering, If I have another class with a jpanel in it... and I add this to the jPanel, this should work correct? jpanel.add(new DoughOverviewList()); jpanel.repaint(); for some reason its not showing in my jpanel, /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package doughtracker; import java.awt.Color; import java.awt.Font; import javax.swing.BorderFactory; import javax.swing.DefaultListModel; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.border.Border; import javax.swing.event.ListSelectionEvent; /** * * @author Acer */ public class DoughOverviewList extends JList { …

Member Avatar
Member Avatar
+0 forum 4

Flickering occurs when Active Rendering with JPanel, not sure why as I've done this before (couldn't find source code of that project however). Relevant Code: Graphics g = projectDCWindow.getWindowGraphics(); // Gets the Graphics Object from a JFrame g.setColor(Color.BLACK); g.fillRect(0, 0, (int) ProjectDCInfo.getDefaultWindowSize().getWidth(), (int) ProjectDCInfo.getDefaultWindowSize().getHeight()); // Clears the screen projectDCGSM.get().render(g); // Game State Manager which simply draws to the Graphics Object g.dispose(); This is where I draw to the Graphics Object, drawX and drawY are being updated g.setColor(Color.BLUE); g.fillRect(drawX, drawY, 100, 200); The JFrame Code private JFrame projectDCWindow; protected ProjectDCWindow() { projectDCWindow = new JFrame(WINDOW_TITLE); projectDCWindow.setPreferredSize(getDefaultWindowSize()); projectDCWindow.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); projectDCWindow.addWindowListener(new WindowAdapter() { @Override …

Member Avatar
Member Avatar
+0 forum 8

I was wondering if it would be more efficient to render a single BufferedImage instead of rendering a bunch of BufferedImages in a double for loop? I have an idea of how to do it, I just don't know what methods in BufferedImage you would use to create the bigger image. I'm assuming it has to do with `setRGB()` but what would the pseudo code look like when using `getRGB` on all the smaller images? The reason I was thinking it would be more efficient to render that way is because you can render only a smaller portion of it …

Member Avatar
Member Avatar
+0 forum 1

I have a custom class which extends JPanel and overrides the paintComponent() method. Here's what that looks like: @Override protected void paintComponent(Graphics g) { if(redrawRequested) { g.setColor(ETCH_BACKGROUND_COLOR); g.fillRect(0, 0, owner.getAppWidth(), owner.getAppHeight()); redrawRequested = false; } g.setColor(Color.BLACK); g.fillRect(pointX, pointY, PIXEL_SIZE, PIXEL_SIZE); } The same custom class also implements KeyListener. I am listening for some keys, and more specifically Space which calls a method requestRepaint(). Here's what that method looks like: public void requestRepaint() { redrawRequested = true; revalidate(); repaint(); } My problem is, when the program starts, whats in the if block inside paintComponent get's fired but the fillRect doesn't work(?) …

Member Avatar
Member Avatar
+0 forum 17

Hello Everyone, I am experiencing errors when trying to compile a project in Java 8. The errors are caused by swing components. The code I am using is the following: import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class Main2 { public Main2(){ JFrame f = new JFrame (); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(100, 100); JPanel p = new JPanel(); JLabel l = new JLabel("Test"); p.add(l); f.add(p); f.setVisible(true); } public static void main(String[] args) { new Main2(); } } The problems are caused by the p.add(l) and the f.add(p). They throw a `The method add(JLabel) is undefined for the type JPanel` and a `The …

Member Avatar
Member Avatar
+0 forum 3

I'm painting a grid on the JPanel and trying to scroll the grid with a JScrollPane. I have a feeling the scrollpane is getting the actual size of the panel, instead of the size including what is not being shown. Something along those lines at least, I can't quite wrap my head around the problem which is why I can't figure it out. Here's the JPanel class that actually get's painted on. /** * Created by GeoDoX on 2015-03-16. */ public class GridPanel extends JPanel { private Tile[][] tiles; private int width, height; private double scale; public GridPanel(int width, int …

Member Avatar
Member Avatar
+0 forum 7

Hello good day. I have an idea for my program. I have a Table in my display. I want to add a Component to - let's say - the right of my screen. When I click this component it should display to me buttons and other components that I have added to it. I want this component is activiated I want it to display from one side of my Frame as a layer over the Table that I have in my display; much like a docked panel or overlay panel. I would love to know how I could accomplish this …

Member Avatar
Member Avatar
+0 forum 10

Hello, I have worked on a project to make a custom-like Internal Frame. There are also other classes which extends it, instead of JInternalFrame. The project works quite good, but there is a problem. The discription of how the JPanel window works: _______________________________________________________________ There is a main JPanel which contians 4 JPanels on every corner. There is also a JPanel called titlebar, Which is the draggable JPanel. All the JPanels have added MouseListener and MouseMotionListener. Whenever the mouse has entered any of the four corner panels, the cursor is changed to NW,NE,SW,SE Resize Cursor. These are draggable, and sets variables …

Member Avatar
Member Avatar
+0 forum 15

I am writing a application.and i need to draw line in jpanel.but it is crash when jpanel add to jframe.this is my code: public class Simplification extends JFrame { JPanel panel; public Simplification(List<List<Integer>> transmitionTable , List<List<Integer>> outTable) { this.setTitle("Simplification Result"); this.setSize(500, 300); this.setLocation(50, 50); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); // do other jobs panel = new JPanel() { protected void paintComponent(Graphics g) { super.paint(g); g.drawLine(0, 0, 11, 11); } }; panel.setVisible(true); this.add(panel); } }

Member Avatar
Member Avatar
+0 forum 1

Hi all, I am having an issue with getting my Jbuttons and JComboBox alignment properly in the JPanel. I have tried changing the coordinates of the GridLayout around to try to satisfy, but they are working properly. I am trying to get my radio buttons to the far right and my combobox and button at the bottom. (See example photo) Below is my code DrawingPane.java package u09.u09.homework.start0; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; import java.awt.GridLayout; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JComboBox; //import javax.swing.JLabel; import javax.swing.JPanel; import …

Member Avatar
Member Avatar
+0 forum 1

Hello Good day. I have an interesting question as it relates to adding a background image to a JPanel (or whichever component is best for what I'm trying to achieve. Hopefully I'll get some help here.) I have a large picture that I want to use as a background image and I want it to be the background for my JFrame. The only thing is that I don't want the image to resize when the JFrame resizes. I want the image to remain centered in relation to the JFrame's position and size, but I just don't want the view of …

Member Avatar
Member Avatar
+0 forum 3

I have developed a piece of software that creates an embedded graph database. I was wondering whether I can use a special feature to visualize it within my program without opening other tools. I am developing my software in JAVA using eclipse and windows builder. I have heard about some libraries like D3 or ZEST but I don't know how to use them. I really want something very easy to attach to a JPanel that shows the database stored in my neo4j folder(Something very simple). May you help me to figure out how to do it? Regards Gaetano

Member Avatar
+0 forum 0

Hello Everyone, I understand this is a basic problem, with a simple solution, but I cannot find a way to fix it. I'm trying to add a Jpanel to a JFrame and when I do the following. g.drawString("HELLO", 500, 0); The string is not seen on screen now if I do g.drawString("HELLO", 500, 5); This can be half-seen at the top, and perfectly if I make the y position 10 pixels. So I guess it has an offset of 10pixels (I don't know if this is the right word). The Frame class its... package Graphics; import java.awt.BorderLayout; import java.awt.Dimension; import …

Member Avatar
Member Avatar
+0 forum 2

Am trying to draw image on jpanel or jlabel when button is been click on, so i added actionperformed on my button as follows. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Image imag = new ImageIcon(this.getClass().getResource("img/top_bg.jpg")).getImage(); showPix1.setLayout(new BorderLayout()); showPix1.add(new paintPhotos(imag,20,20), BorderLayout.CENTER); } I have a separate class called paintPhotos that extends jLabel as follows package myApp; import java.awt.*; import javax.swing.*; public class paintPhotos extends javax.swing.JLabel { public Image img; int w; int h; public paintPhotos(Image img, int w, int h) { this.img = img; this.w = w; this.h = h; System.out.println("am paintclass"); } @Override public …

Member Avatar
Member Avatar
+0 forum 7

Hi guys, i am trying to add a image as the background for my project but cant get my code right, heres what I got so far //beginning of 1 import java.awt.Graphics2D; import java.awt.Toolkit; import java.awt.image.BufferedImage; import javax.swing.JPanel; /** */ public class makeB extends JPanel { private BufferedImage buffer; private void initialise() { buffer = new BufferedImage(700, 500, BufferedImage.TYPE_INT_RGB); } private void drawBuffer() { Graphics2D b = buffer.createGraphics(); createBackGround.makeBackground(b,this); b.dispose(); } private void drawScreen() { Graphics2D g = (Graphics2D) this.getGraphics(); g.drawImage(buffer, 0, 0, this); Toolkit.getDefaultToolkit().sync(); g.dispose(); } public void startGame() { initialise(); drawBuffer(); drawScreen(); } } //end //beginning of 2 …

Member Avatar
Member Avatar
+0 forum 4

i cant seem to print imageicon in board.java. any ideas? i got two files. board.java and WorldBackground.java i have a WorldBackground.java where i am create background image import java.awt.Image; import javax.swing.ImageIcon; public class WorldBackground { static ImageIcon background = new ImageIcon(WorldBackground.class.getResource("Images/backg.jpg")); public static Image getBackground() { return background.getImage(); } } than i am call background image in board.java. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Board extends JPanel implements ActionListener { Timer time; static Graphics2D drawer; /*** constructor Method***/ public Board() { setFocusable(true); time = new Timer(10, this); } public void actionPerformed(ActionEvent e) { repaint(); } public void paint(Graphics …

Member Avatar
Member Avatar
+0 forum 1

Hello everyone. 1)I am trying several days now to display an image from file Chooser in Netbeans. i have read and tried many different approaches from the web, but something goes wrong.Although the program runs ok,I see no results.Until now, I have used the "Design" tab of Netbeans to create one main Jframe and three Panels. Panel1 for image preview(of course I will implement it much later) Panel2 for buttons like "Add pic","remove" etc.The Add button opens my file Chooser.Now I am trying to load an image from the file Chooser inside Panel3 and of course fit it correctly according …

Member Avatar
Member Avatar
+0 forum 17

I want to add squares onto a jpanel one at a time after a delay . My program works fine until I tried to change the background color with setBackgound(). It didn't change. I worked out I have to call super.paintComponent(gr) in my paintComponent method. But when I do this and call repaint(), only the current square is displayed. The previous one's have disappeared. I know it is because repaint is displaying a whole new panel each time but why does it work when I don't call super.paintComponent(). Here is a simplified version of ghe code import java.awt.*; import javax.swing.*; …

Member Avatar
Member Avatar
+0 forum 1

I am working on a project where i need to dynamically count how many buttons need to be added to a certain panel. Each button press has to change a variable in the parent class and then to excute generation of a child panel which also dynamically generates buttons. my problem is that even though I am able to generate the buttons, and add them to the layout, I dont know how to change their individual actionlisteners. The code I have right now is this: private void PopulateBooks() { for (int i = 0; i < 14; i++) { books.add(new …

Member Avatar
Member Avatar
+0 forum 1

Hello, I am having some trouble writing this java GUI. First in the win1, i cannot get the start and exit button to the bottom of the page along with the jlabel into the center. Next for win2 i cannot resize the "go here" button at the bottom of the page. also from win2 i cant get he add button to update the contents of the jlist, ie click add, write in servers name, and have it appear on the list. the code i have comment out in win2 is what i thought i needed, but I cannot get it …

Member Avatar
+0 forum 0

I have a JLabel and a JPanel which both implements MouseClicked methods and I have added the JLabel to the JPanel but when the JLabel is clicked, the MouseClicked method of JPanel is invoked. How to fix this>??

Member Avatar
Member Avatar
+0 forum 1

Hi Sorry i was doing a little program and i need helps i would like to something similar to that [url]http://i42.tinypic.com/2mys23d.png[/url] this is my code so far [code] private void makeFrame() { frame = new JFrame("Jubilee Estate Agency Property"); makeMenuBar(frame); Container contentPane = frame.getContentPane(); JLabel label = new JLabel(); contentPane.add(label); // building is done - arrange the components and show frame.pack(); frame.setVisible(true); // Specify the layout manager with nice spacing contentPane.setLayout(new BorderLayout(2, 2)); statusLabel = new JLabel(CONTACT); contentPane.add(statusLabel, BorderLayout.SOUTH); frame.pack(); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(d.width/2 - frame.getWidth()/2, d.height/2 - frame.getHeight()/2); frame.setVisible(true);[/code] and i would like know how I can put …

Member Avatar
Member Avatar
+0 forum 6

Hello, I'm trying to make a JPanel with JFrame capabilities, such as resizing, and moving, Everything seems to work fine, altough there are minor flickering inside the JPanel, I have numeral repaints and I have a method called update(), which uses absolute position to arrange Containers and Components. Whenever the JPanel is resized, update() is called. This is a 2 part problem. 1. Flickering. 2. Cant get a container from another class to get resized within the JPanel. Is there any way to resolve these problems? [CODE]import java.awt.*; import java.awt.event.*; import javax.swing.*; public class sys_windows extends JPanel implements ActionListener, MouseMotionListener, …

Member Avatar
Member Avatar
+0 forum 11

I'm trying to get my JPanel (JFrame?) to resize itself to fit randomly drawn shapes. I have a shape superclass and right now I'm working with my line subclass. Everything is working fine except I can't figure out how to make the shapes fit the size of the JPanel. Should I limit the size of the shapes or could someone suggest a way to dynamically set the size of the Jpanel based on the maximum size of the shapes? (I'll eventually want to do this with several shape types in the same panel). I'm thinking a for loop grabbing the …

Member Avatar
Member Avatar
+0 forum 3

I'm having problems adding a JPanel, which has a paintComponent in it, to a JFrame. If this is the only thing I add to the frame, it works. But as soon as I add a layout manager and add other components to the JFrame, it no longer shows the panel with the painting! To make this clearer ... This is the code that works and the JPanel is successfully shown: The panel that draws the sign (in reality i am not trying to paint hello, this is to simply the code here) [CODE] public class SignPanel2 extends JPanel { public …

Member Avatar
Member Avatar
+0 forum 3

im creating a prototype for a hotel using netbeans ide 7.0. I used the drag and drop in designing the buttons, panels, label etc... then what i want to happen is when the button is clicked a jpanel/ jframe that i did will appear. How would i do that? I don't even know whats that called so i am having a hard time searching it in the net. All help is appreciated. Thank you.

Member Avatar
Member Avatar
+0 forum 5

Hi daniwebbers, I am a newbie learning java and keep getting a "cannot find symbol" error when I try to compile my program. I've tried searching but I don't really know what search terms I should be using in this case. Can anyone see the problem? [CODE]import javax.swing.*; import java.awt.event.*; class menuFrame extends JFrame implements ActionListener{ public static void main(String[] args){ new menuFrame(); } public menuFrame(){ JPanel menuPanel = new JPanel(); menuPanel.setLayout(null); JLabel lblName = new JLabel("Name: "); lblName.setBounds(30, 20, 100, 20); JTextField txtName = new JTextField(15); txtName.setBounds(80,20,150,20); JButton btnStart = new JButton("Start"); btnStart.setBounds(90,60,100,20); menuPanel.add(lblName); menuPanel.add(txtName); menuPanel.add(btnStart); setDefaultProperties(); } public …

Member Avatar
Member Avatar
+0 forum 9

I've been searching the internet for a way to specify the size of a component within a JPanel, but I haven't been able to find anything that has worked. The best answer I came across was to override the getPreferredSize(), getMaximumSize(), and getMinimumSize() methods of the component, but the component still took up the entire available space within the JPanel. For the sake of argument, let's say I'm trying to define a custom size for a JTextArea inside a JPanel using a BoxLayout. What is the best way to stop the Layout Manager from resizing my components to take up …

Member Avatar
Member Avatar
+0 forum 4

Hi, I am a new Java Programmer.could you help me in resolving this. I am trying to created a JPanel withing a main JPanel. For the nested one, i have included Grid Layout and i am trying to add components to it dynamically. i.e i have added a combo box to the nested JPanel and based on the selection it makes, i want to add few more components to the same JPanel. For this i created some code, but the problem is irrespective of the size, i mention for the combo box, it takes up the whole size of the …

Member Avatar
Member Avatar
+0 forum 6

I need some help. I'm trying to create a number pad like a cellphone that captures user input by pressing buttons in a panel on the left and displaying what the user punches in the top panel. Then I have a clear button in the panel on the right to clear all, but I can't get it to work. Am I close? [code] package keypad; import java.awt.*; import javax.swing.*; import javax.swing.JLabel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class KeyPadPanel extends JFrame implements ActionListener { private JLabel display; private JButton one, two, three, four, five, six, seven, eight, nine, zero, asterick, pound, …

Member Avatar
Member Avatar
+0 forum 7

The End.