jpanel

Simple JFrame dialog displaying JButton

First off, I am real new to Java Swing/AWT and not intricately familiar with the workings of JFrame, JPanel & JButton. I want to just display a simple PopUp dialog with a some text and a couple JButtons and it should exit when any of the two buttons are clicked. I have most of that logic in this class, however I'm still struggling to mak...

Drawing in Java without a JPanel

I'm writing a graphical user interface to plot data on a xy-axis. It's written in Java Swing so I have a JFrame that contains the whole GUI. One of the components of the GUI is a JPanel that makes up the area where the data is plotted. I use Graphics2D to do my drawing. I'm trying to make a command line extension of this program. Th...

Non-Working paintComponent method

Code : import javax.swing.*; import java.awt.*; public class firstGUI extends JPanel { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500,500); frame.setVisible(true); } public void paintComponent(Gr...

get rid of some parts of png in java

In my program,I am producing a png from a panel,but I want to get rid of the bounding box of this panel and to be more focused to the object in the panel.To do so, I want to get rid of the peripheral parts of png, and produce only the center of it.How can i do that ? ...

Running JPanels in their own threads.

I'm having a bit of trouble with Swing components. In one JFrame, I have a GLCanvas and a JEditorPane separated by a JSplitPane. This configuration makes display response choppy in both panels. However, when I place the GLCanvas and JEditorPane each in their own JFrame, display response is great. I would assume this is because, in ...

drawing a graph in a JPanel in Net Beans

Hi Is there a possible way to override the paintComponent() method in the auto-generated GUI code in NetBeans? I managed to manually draw a graph without using the drag-and-drop components, and I need to make adjustments (e.g. adding radio button group) which I find really time consuming and tedious work. I created a GUI using the Net...

add a scrollable jpanel to a gridlayout

Hello, I'm building a grid filled with labels. One of them contains html-text and should resize to maximum format and be scrollable. I found how to add a JScrollPane but it stays one line height, I just can't find how to resize it even when I give it a size of 400x400 ... Removing getViewport() gives the same result. JPanel grid = new...

Java Swing - JLabel Location

Hi, I have problem while setting the Jlabel location. I set the content pane to some JPanel, I created and tried to add my JLabel. JLabel mainTitle = new JLabel("SomeApp"); mainTitle.setFont(new Font("Arial",2 , 28)); mainTitle.setBounds(0,0, 115, 130); getContentPane().add(mainTitle); I want that my JPanel will be on...

How To Access Controls On a JPanel...?

I'm a Java n0ob....so let me apologize in advance... I've got a jPanel that I've added a bunch of controls to, dynamically, at run-time. Later, in my code, I want to loop through all of those controls (they are jCheckBoxes) to see if they are checked or not. In .NET - I'd be looking at some like... For Each myControl as Control In my...

JTabbedPane tabs

Alright, so I have a JTabbedPane in an application and it has several panels. Is it possible to assign a JPopupMenu to the actual tabs themselves instead of the JPanel? If it is possible, how would I do this? ...

Change a child Component using a JPanel reference?

Hi. I have a JPanel panel with a bill designed and populated inside it. I passed it to a printer function - which used iText to save it to a pdf. The basic flow of code is like this. void printToPdf(JPanel panel) { ... Image toEmbed = generateImage(panel); doc.add(toEmbed) ... } Now, according to the new requireme...

MouseListener for JPanel missing mouseClicked events

I have a JPanel that I have created a MouseListener for and I am seeing some behavior that I can't explain. Usually when I click the mouse within the JPanel, I see the following events fire: mousePressed mouseReleased mouseClicked On some occasions, I don't see the mouseClicked event fire, I only see: mousePressed mouseReleased I...

Java - Custom Shape Panels?

I am working on an application that involves the user requiring to hover over several moving dots on the screen in order to launch specific popups. At the moment, i am listening for mouseMoved events on the JPanel onto which the dots are rendered, and then launching the required pop ups whenever the cursor is within a specific distance o...

Passing font to components on a JPanel

I have a class that extends JPanel with several buttons on it. I would like to be able to set the font on all the buttons with one call to setFont(Font font); I defined the setFont method in the JPanel class as such: public class MyPanel extends JPanel { private JButton[] buttons = new JButton[10]; public MyPanel() { f...

Java: Handling event on component inside a seperate JPanel component

Hey guys, So I have a JFrame which I've added a custom JPanel component. The JPanel component has a button that I want to attach a listener to in my JFrame. What is the best way to do this? ...

Java: getting the absolute position of the mouse in a JPanel given the coordinate the user clicked on.

For example, suppose I have a drawing in a JPanel subclass with JScrollPanes, and I want to capture the points the user clicks on. Suppose, for example, the drawing area inside the JPanel goes from 0 to 10000, while the screen size isn't known a priori. Given the mouse coordinates in the click event thing, is it possible to determine whe...

In Java/Swing, is it ok to make new "main" JPanel objects when required by the user?

Hi folks, I am curious whether it is good practice to make a new main JPanel object every time a user wishes to return to that JPanel from a subsequent JPanel? FYI, my Swing application has a JFrame whose first object is a mainJPanel with three JButtons (one of them is a Review button). Let's say the user pushes the Review button. The...

Difference between JPanel, JFrame, JComponent, and JApplet

Hi, im making a physics simulator for fun and i was looking up graphics tutorials when i tried to figure out the difference between all these J's. could somebody elaborate on them or perhaps provide a link to a helpful source? ...

How to pass value (array or arraylist) from 1 pane to another pane?

This is my main class code: public static void main(String[] args) { JFrame f= new JFrame ("My Frame"); f.setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE); JTabbedPane tp = new JTabbedPane(); tp.addTab("Pane1", new PaneFirst()); tp.addTab("Pane2", new PaneSecond()); f.add(tp); f.pack(); f.setVisible(true); } In PaneFirst, ...

Position a Jpanel In the middle of a Jframe or Another Jpanel

I am making a card game atm, and i want the card stack to be placed in the middle of a Jframe. Right now i have made the cardstack in a layeredPane. And that layeredPane is placed in a panel. And i want that panel to be placed in the midle of the frame, or the contentpanepanel.... Please help guys... I dont want more sleepless nights...