jcomponent

Is there anywhere we can find the actual code of the Actions in framework-supplied ActionMaps?

こ雲淡風輕ζ 提交于 2019-12-11 10:55:14
问题 The particular thing I'm interested in at the moment is JTable's 'cancel' Action ... in particular I'm trying to find out why, with an InputVerifier set for the JTable's CellEditor's Component (JTextField), the IV's shouldYieldFocus() method is called not once, but twice (!) when I press Escape. I have checked that it is the JTable's ActionMap entry for VK_CANCEL ('cancel') which is being run here. Furthermore I find that the JTable's editingCanceled method is NOT called when I press Escape

All parts of my Printable Swing component doesn't print

China☆狼群 提交于 2019-12-11 08:54:28
问题 I'm trying to do a printable component (an invoice document). I use JComponent instead of JPanel because I don't want a background. The component has many subcomponents. The main component implements Printable and has a print -method that is calling printAll(g) so that all subcomponents should be printed. But my subcomponents doesn't print. What am I missing? Does all subcomponents also has to implement Printable? In my code below, the TopHeader is not printed. import java.awt.BorderLayout;

How to add KeyListener to JComponent when mouse is entered?

二次信任 提交于 2019-12-11 08:24:54
问题 I have created custom button class which extends JComponent and want to add KeyListener on mouseEntered event (and later remove on mouseExited ). So my goal is - when the mouse enters this JComponent - then if I press Enter - some code will be executed, related to only this button. How can I do that? 回答1: Use Key Bindings instead of KeyListeners, since the latter is way to low level for Swing . Just bring your mouse over the JButton , and then press ENTER , then take your mouse outside the

export jcomponent to PDF with iText

柔情痞子 提交于 2019-12-11 08:24:39
问题 Id like to export my jcomponent (custom paintcomponent method which draws a lot of texts and lines, small images (kind of a small word application)) to PDF my component is "bill" the method i use for this (which works, but some methods are deprecated) is: com.itextpdf.text.Rectangle r = new com.itextpdf.text.Rectangle(0,0,bill.getWidth(),bill.getHeight()); Document document = new Document(r); try { PdfWriter writer; writer = PdfWriter.getInstance(document, new FileOutputStream(f)); document

How to draw a triangle with border with Java Graphics

不想你离开。 提交于 2019-12-11 05:50:00
问题 I'm trying to draw a triangle with a border using the Graphics.drawPolygon() method The triangle is properly drawn, but how can I calculate the 3 points of the border? I already did it with a circle, but I can't seem to find a solution for triangle. A requirement of the instructor as that it cannot use Graphics2D . My code: if (xPoints != null && yPoints != null) { int[] nXPoints = new int[] { xPoints[0] - borderThickness, xPoints[1] - borderThickness, xPoints[2] - borderThickness }; int[]

How to use z axis?

橙三吉。 提交于 2019-12-11 03:16:22
问题 I have a code, which imports a brain image, I wanted to know that can how can I use the third axis, i-e z axis, (far and near axis) so that I can position the image facing upwards,(not facing user) so that outline of image is visible. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.geom.*; import java.applet.*; import java.net.URL; public class Brain extends JComponent { static int x = 200; static int y = 200; static int currentAngle = 0; static double hspeed

the five top rows of the oval are erased. why?

这一生的挚爱 提交于 2019-12-11 02:35:11
问题 I'm really confused, I tried setting the oval to be exactly inside the red JPanel and the oval went 5 pixels too low. I tried to change y1 to -5 so it would be exactly in the JPanel, the oval moved to the right place but the five top rows of the oval were erased why did these things happen? and how do I place the oval in the middle of the JPanel? package il.co.atlantis; import javax.swing.*; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; public class PanelExample

How to add a scrollbar for long JComponents in a JPanel? How to center a JComponent?

ε祈祈猫儿з 提交于 2019-12-11 01:43:56
问题 Currently, I have to JComponents contained in a JPanel with a vertical box layout. This way, I can have the first component centered, as shown below, and have the bottom component (which is quite long) below. However, since the bottom component is very long I wanted to add a slider just for that specific component. This way, the user can see all of the bottom component with the upper component remaining centered. However, my code below doesn't fix anything and the scrollbar never even works.

How to paint JComponent in JComponent?

久未见 提交于 2019-12-11 00:18:44
问题 I have strange problem with JComponent. I am trying to create my own JComponent and so I need to compose my JComponents together. I wanted to paint JButton in my JComponent JDial: public class JDial extends JComponent { private static final long serialVersionUID = 3364481508702147328L; public JDial() { JButton b = new JButton("test"); this.add(b); } } But that just paint nothing. Even more interesting is that this one works well: public class JDial extends JPanel { private static final long

How does JComponent.paintImmediately() work in Java Swing?

大兔子大兔子 提交于 2019-12-10 01:47:37
问题 My understanding: Unlike most of the components/operations in Swing call to JComponent.repaint() is thread-safe i.e. though a repaint request is made from another thread (i.e. not from EDT), the actual painting happens in EDT only. Below code snippet demonstrates this. public class PaintingDemo { public static void main(String[] args) { final JFrame frame = new JFrame(); final JPanel p = new MyPanel(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { frame.add(p,