jcomponent

Difference between JPanel, JFrame, JComponent, and JApplet

允我心安 提交于 2019-12-04 07:30:24
问题 I'm 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. Can somebody elaborate on them or perhaps provide a link to a helpful source? 回答1: Those classes are common extension points for Java UI designs. First off, realize that they don't necessarily have much to do with each other directly, so trying to find a relationship between them might be counterproductive. JApplet - A base class that let's you write

How to check whether JComponent inside JScrollPane is visible to a user?

北城以北 提交于 2019-12-04 07:21:13
Imagine you have a JScrollPane and many JLabel s or any other JComponent s added to it. How would you check if a certain component is visible/partially visible/not visible to user? (scrolling) I have tried to Google but could not find an easy solution. Is there some existing method I am missing or we have to deal with coordinates and rectangular comparison? UPD: the following is not working in my case. It seem to relate to JLabel.setVisible(true/false) but not being inside JScrollPane JLabel.isVisible(); Have a look at JComponent java doc: Rectangle r = child.getVisibleRect(); if (r.getSize()

How do I get the image paint/paintComponent generates?

心不动则不痛 提交于 2019-12-03 15:41:18
I have a quick question. How do I get the image generated by a JComponent.paint or paintComponent? I have a JComponent which I use as a 'workspace' and where I have overwritten the paintComponent method to my own. The thing is that my workspace JComponent also has children which has their own paintComponent methods. So when Swing renders my workspace component, it renders the workspace graphics and then its childrens'. However, I want to get the image my workspace component generates (which includes the workspace graphics and the children's graphics). How do I do that? I tried to call the

JSplitPane splitting 50% precisely

徘徊边缘 提交于 2019-12-03 02:19:22
In Swing, what's the best way to make the JSplitPane to split two jpanels with 50% size each. It looks like if I don't set preferred sizes on the panels it always makes the first panel almost invisible (2%) and the second one (98%) Thanks in advance Use setResizeWeight (.5d); [...] A value of 0, the default, indicates the right/bottom component gets all the extra space (the left/top component acts fixed), where as a value of 1 specifies the left/top component gets all the extra space (the right/bottom component acts fixed). [...] You should use setDividerLocation(double proportionalLocation)

Java - draw circle after clicking button

三世轮回 提交于 2019-12-02 17:09:21
问题 I am trying to draw a circle with the press of a button in java. I put the System.out.println() inside the action method to make sure my code was working. The println shows up but no circle drawing anywhere. Any Suggestions? Thank you import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public class CircleViewer { public static void main(String[] args) {

Difference between JPanel, JFrame, JComponent, and JApplet

ぐ巨炮叔叔 提交于 2019-12-02 16:04:54
I'm 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. Can somebody elaborate on them or perhaps provide a link to a helpful source? Those classes are common extension points for Java UI designs. First off, realize that they don't necessarily have much to do with each other directly, so trying to find a relationship between them might be counterproductive. JApplet - A base class that let's you write code that will run within the context of a browser, like for an interactive web page. This is cool and all

Why .paintComponent() is defined on JComponent?

霸气de小男生 提交于 2019-12-02 10:47:00
Sorry if my question doesn't adjust to the Stackoverflow requirements due to it is theorical but i don't know where else to ask. For the past few weeks i've been trying to understand better how the Swing API works and it's components in order to create my own custom components. I've read tons of tutorials, searched in here, i am neck-deep in Java's swing source code and frankly... my mind is a mess. As far as i understand, the swing components are composed of 3 parts: the model: where the component state and data are stored the UI delegate: which paints the component and the JComponent: it

JFrame - mouse click using JComponent and MouseListener

我怕爱的太早我们不能终老 提交于 2019-12-02 08:00:33
问题 Having 2 classes - public class MainClass { public static void main(String[] args) { JFrame frame = new JFrame(); .... Component mouseClick = new MyComponent() ; frame.setVisible(true); } public class MyComponent extends JComponent implements MouseListener { @Override public void mouseClicked(MouseEvent arg0) { System.out.println("here was a click ! "); } ... } I trying to set on the frame a listener for mouse click , but when I run it and then press mouse click nothing happens . How to make

How to add time delay between adding components to JFrame?

微笑、不失礼 提交于 2019-12-02 05:24:47
问题 I created a JFrame, and it contains a JPanel. I created a number of JLabels. I can add the JLabels to the JPanel, and display them correctly. But I want to implement them so as they displayed sequentially ; a time delay between each JLabel to be displayed. After searching the StackOverfLow, I tried some code, but it has no effect!. So How to use a timer to make components(Labels) displayed one after the other by setting a time delay. I Don't want a fix for my code particularly in the answer.

How to add time delay between adding components to JFrame?

大兔子大兔子 提交于 2019-12-02 01:59:10
I created a JFrame, and it contains a JPanel. I created a number of JLabels. I can add the JLabels to the JPanel, and display them correctly. But I want to implement them so as they displayed sequentially ; a time delay between each JLabel to be displayed. After searching the StackOverfLow, I tried some code, but it has no effect!. So How to use a timer to make components(Labels) displayed one after the other by setting a time delay. I Don't want a fix for my code particularly in the answer. Just show how to display any type of components in a delayed manner, each component displayed after a