jpanel

Getting the (starting) X and Y coordinates of a Path2D shape drawn on Jpanel

送分小仙女□ 提交于 2019-12-12 07:07:32
问题 So, I have a program where I can add shapes to JPanel using Path2D objects and then I can click and drag them around. What I want to do is be able to find the final X and Y coordinates of the shape AFTER it has been drug. The coordinates need to be the top-left coordinates . Any ideas? // add a circle to center of the screen public void addCircle(int width, int height) { Path2D circ = new Path2D.Double(); circ.append(new Ellipse2D.Double(getWidth() / 2 - width / 2, getHeight() / 2 - height /

How to draw multiple shapes on JComponent or Jpanel?

孤街浪徒 提交于 2019-12-12 06:48:05
问题 I'm trying to build Paint app and I doing something wrong in DrawingArea class. The problem is when I try to draw second shape , the first shape or figure is auto deleting so I need to some idea about how to solve this.All answers acceptable. THANKS FOR HELP. There is part of DrawingArea.class codes : @Override // GETTING FIRST (STARTING) COORDINATE WHEN THE MOUSE PRESSED public void mousePressed(MouseEvent e) { oldX = e.getX(); oldY = e.getY(); repaint(); } @Override // GETTING RELEASED

Resizeable Number Pyramid Panel with Swing

最后都变了- 提交于 2019-12-12 06:28:20
问题 I am trying to create a resizable window with Swing and AWT components which displays numbers in a pyramid fashion depending on what the frame is sized to but I have no idea really where to start. I am not sure if I am supposed to use JLabel or StringBuilder. If it can be done without using action listeners, that would be preferred. I need some assistance. 回答1: I would simply create a dedicated panel and override the method paintComponent. Then using the FontMetrics and the size of that panel

How to set scroll to the top - JPanel that has multiple JTextareas inside Jscrollpane

主宰稳场 提交于 2019-12-12 05:52:33
问题 I have a JPanel in a JScrollPane. The JPanel contains multiple JTextAreas vertically. I like to keep the scroll of the scrollpane to the top whenever the page is refreshed. Currently, the scroll always starts from the bottom. this is my current code and it doesn't work.. panel.invalidate(); panel.revalidate(); panel.repaint(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { ((JPanel) panel).setLocation(new Point(0, 0)); } }); I've also tried adding this code below to

Communicating between JPanels

丶灬走出姿态 提交于 2019-12-12 05:38:47
问题 First off, I'm new to Java, so please be gentle. I have a JFrame which has two 'JPanels', one of which is a separate class (i've extended the JPanel). Ideally I'd like to 'dispatch and event' or notify the other JPanel object on the JFrame. I have an array of JButtons in the custom JPanel class, which i'd like to add an event listener to. Upon clicking the JButton, i'd like to change something on the other JPanel. I'm really not sure how to do this, so I moved the event handler into the

Design: extend JPanel twice or pass JPanel as parameter?

ぐ巨炮叔叔 提交于 2019-12-12 05:17:30
问题 I have design issue here. There two options which sound possible to implement but I don't like neither one. I need to provide two functionality in my JPanel. draw several lines draw several strings ads Approach extend twice If I would need only to draw lines then I can just copy-past solution from the following answer. Draw a line in a JPanel with button click in Java public class LinePanel extends JPanel { ... @Override protected void paintComponent(Graphics g) { super.paintComponent(g); ...

JList with changing Height

时间秒杀一切 提交于 2019-12-12 04:57:54
问题 I got a JList, which i want to change height of depended on how many items within the JList. As seen in the picture, theres alot of components inside a JPanel, which all are alligned at the Y axis. (the JScrollPanel belongs to the JPanel, NOT the JList) I would like the JList to match its height with the amount of items. A normal JList just stops showing items if it gets too big (unless you apply a JScrollPane).. What i simply want to, is that the JList will get the right size (without hiding

KeyListener won't listen on JPanel

强颜欢笑 提交于 2019-12-12 04:55:48
问题 It's a very simple program, but for some reason when I debug it and set breakpoints at the keyPressed , keyReleased and keyTyped method, the program never stops there. mainKeyListener = new KeyListener() { public void keyPressed(KeyEvent e) { System.out.println("KEY PRESSED"); repaint(); } } @Override public void keyReleased(KeyEvent arg0) { // TODO Auto-generated method stub } @Override public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub } }; Here I add it to a JPanel ,

Layering text over JLabel

一个人想着一个人 提交于 2019-12-12 04:46:15
问题 This is how I want my app to look like. Trouble is, if I drag the JLabel with the "Hello, I'm Myra" over another JLabel (whose icon is the speech bubble), rather than superimposing or layering, NetBeans shifts the JLabels to be adjacent. How do I superimpose ie. place the text JLabel on top of another JLabel? Do note, I'm using NetBeans. It doesn't allow me to edit much of the JFrame or JLabel code. 回答1: Netbeans won't let you add components to a JLabel , it doesn't see them as a valid

Updating JTabbedPane when new tab is added

二次信任 提交于 2019-12-12 04:43:47
问题 I'm working on a project, and have run into a little bit of a logic error, hopefully one of you can clear this up. I'm building an application that will display a SQL database (among other things). Currently, the way I have things set up, I have a JTabbedPane inside a Container (BorderLayout.CENTER) not that this is really pertinent information. Anywho, I would like to add a tab once the user has connected to a database (and eventually selected which 'table' to see. For now however, there is