jcomponent

JFrame code compiles and runs, but does not open window

我与影子孤独终老i 提交于 2019-12-24 22:57:18
问题 Here you will see my code: I am just trying to make a little window that displays "Hello, Java!". I am currently running on Ubuntu 14.04. To go more in depth with my problem, the icon with the coffee cup shows up when I run the program like there is a window, but there is not window attached to it and if clicked, no window pops up. Any help would be much appreciated! public class HelloJava1 extends javax.swing.JComponent { public static void main(String[] args) { javax.swing.JFrame f = new

Java/Swing offscreen rendering (Cobra HTMLPanel -> BufferedImage) Problem: Component doesn't finish redrawing first

馋奶兔 提交于 2019-12-24 16:27:49
问题 I'm trying to render the contents of a the Java/Swing Cobra HTML renderer to an offscreen BufferedImage, for use elsewhere in my app: slideViewPanel.setDocument(document, rendererContext); BufferedImage test = new BufferedImage(300,300,BufferedImage.TYPE_INT_RGB); Graphics g = test.getGraphics(); slideViewPanel.paint(g); The resulting image in g shows a partially rendered page -- sometimes the contents of the HTMLFrame before the new document was set; sometimes a half-rendered version of the

Graphics Not Drawn/Appearing

我怕爱的太早我们不能终老 提交于 2019-12-24 07:17:37
问题 I'm having this problem where an object that I've drawn isn't appearing in the GUI. I know it's being processed because data is being pushed to a log file. However, the graphic isn't appearing. Here's some of my code: public static void main(String[] args) { JFrame window = new JFrame(); window.setLayout(new BorderLayout()); window.setVisible(true); } There's a button and a few other widgets that I've placed here and there. The center pane (BorderLayout.CENTER) is where my DrawnObject is to

Drawing a JComponent inside a JPanel

梦想的初衷 提交于 2019-12-22 20:46:50
问题 I am trying to display a JComponent inside a JPanel. I am using null layout because location of the components can be changed during runtime and I have to control them. But the following code does not work. The JComponent only becomes visible on display if I explicity call the "paintComponent" method, which I think is not good practice. My JComponent Class public class MyIcon extends JComponent { private double xPos; private double yPos; private double radius = 30; public MyIcon(double xPos,

Drawing a JComponent inside a JPanel

不羁的心 提交于 2019-12-22 20:46:12
问题 I am trying to display a JComponent inside a JPanel. I am using null layout because location of the components can be changed during runtime and I have to control them. But the following code does not work. The JComponent only becomes visible on display if I explicity call the "paintComponent" method, which I think is not good practice. My JComponent Class public class MyIcon extends JComponent { private double xPos; private double yPos; private double radius = 30; public MyIcon(double xPos,

Get all swing components in a container

南楼画角 提交于 2019-12-22 11:21:02
问题 I think we can use jScrollPane.getComponents() to get awt components of a jscrollpane. My question is: is there a way to get swing components of a container some how? 回答1: All Swing components extend JComponent. Component[] comps = jScrollPane.getComponents(); ArrayList<JComponent> swingComps = new ArrayList<JComponent>(); for(Component comp : comps) { if(comp instanceof JComponent) { swingComps.add((JComponent) comp); } } 回答2: You can call getComponents then test to see if it is an instance

The JPanel contentpane confusion

我怕爱的太早我们不能终老 提交于 2019-12-22 06:39:18
问题 I am learning Java Swing and I appended a menuBar to the frame. By default this should call jframe.getContentPane().add(child) . When I ran the script the menuBar didn't show up. But the button was at the very top "y=0" if that makes sense. Then I realized my mistake I actually had to put in a menu in the menubar. Then the menuBar showed up. So that got me thinking...is the "menubar" "contentpane" actually 2 panels? It is confusing the hell out of me. Because that acted a lot like a panel.

JSplitPane splitting 50% precisely

安稳与你 提交于 2019-12-20 11:11:50
问题 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 回答1: 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

JSplitPane splitting 50% precisely

感情迁移 提交于 2019-12-20 11:11:33
问题 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 回答1: 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

Why .paintComponent() is defined on JComponent?

扶醉桌前 提交于 2019-12-20 06:49:15
问题 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