jpanel

JButton Positioning Issues

风格不统一 提交于 2019-12-22 12:21:35
问题 Okay, I have a Jpanel which is shown as white in the below image using an overlay layout. It holds a ScrollPane holding an image ("No Image Available") and a JButton ("Comment"). I want to position this button in the bottom right hand corner of the JPanel. I have tried multiple layout approaches and I cant seem to get it to work. At most the button moves about 3/4 of the way South-East and I have no idea why. Any help is greatly appreciated.. 回答1: There are a lot of possible solutions using

JButton Positioning Issues

喜你入骨 提交于 2019-12-22 12:20:08
问题 Okay, I have a Jpanel which is shown as white in the below image using an overlay layout. It holds a ScrollPane holding an image ("No Image Available") and a JButton ("Comment"). I want to position this button in the bottom right hand corner of the JPanel. I have tried multiple layout approaches and I cant seem to get it to work. At most the button moves about 3/4 of the way South-East and I have no idea why. Any help is greatly appreciated.. 回答1: There are a lot of possible solutions using

Java return from a ShowOptionDialog from an inner JPanel

白昼怎懂夜的黑 提交于 2019-12-22 10:48:54
问题 I used JOptionPane.showOptionDialog(null, new MyPanel(), "Import", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[]{}, null); because I don't want the default buttons provided by the OptionDialog and I created my buttons inside the MyPanel extends JPanel So my problem is now how can I close that OptionDialog from inside the MyPanel fired by an ActionEvent ? I don't care the return value, as long as that dialog disappears. And I realize this might not be the best

Java align JLabel in center of JPanel

安稳与你 提交于 2019-12-22 05:24:39
问题 I have a bar at the top of my application that has a number of buttons either side of a JLabel. The button's visibility is dependent upon the current task a user is carrying out and one of the button's text may also change depending on the current state. What I would like to do is have a number of buttons stick to the left of the JPanel, the JLabel's center to be in the very center of the JPanel and the rest of the buttons to be to the right of the JPanel. So far I have managed to get the

How to reset a JTable

蹲街弑〆低调 提交于 2019-12-22 00:34:33
问题 I have a question with respect to JScrollPane and a JTable . I have added a JTable to a JScrollPane , and added the JScrollPane to the JPanel . When I click on 'show' button, the JTable will be filled with contents from the database. I also have another button reset , clicking on which will remove the contents of the JTable , and the JScrollPane . It is supposed to be doing that, but what happens is that, even after clicking the button, all the contents of the JTable and the JScrollPane still

Drawing a movable line on a JPanel

会有一股神秘感。 提交于 2019-12-22 00:19:03
问题 I'm writing a program which should allow the user to create a floor plan of a room - this means they can draw lines to represent walls etc. I am using a JPanel with Graphics 2D to do all the drawing stuff and currently I have a grid set as the background for the JPanel and I can draw lines based on the mouse movement(I have an enum for the mousestate with two states - DRAGGING and IDLE). However I want to add control points to the lines so that they can be moved around the JPanel once they

How to add imagepanel in jpanel inside Jframe?

二次信任 提交于 2019-12-22 00:00:06
问题 I'm trying to add an imagepanel which extends JPanel to another JPanel. Which is not working well for me. The paint function of image panel don't get invoked inside Jpanel but works fine in JFrame. Any ideas or help will be appreciated. import javax.swing.*; import java.awt.*; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; class ImagePanel extends JPanel { int g_h=10,g_w=10; int width=50,height=50; int cornerradius; Image castle; Dimension size; protected int x1

MouseEvent lost in JScrollPane

旧时模样 提交于 2019-12-21 20:09:59
问题 This is the code I am using to show the issue which I am facing in another project. I am not getting any line like this if I use JScrollPane as a wrapper for panel2. Why? I want to click on JscrollPane and got event printed as following. java.awt.event.MouseEvent[MOUSE_CLICKED,(800,469),absolute(808,499),button=1,modifiers=Button1,clickCount=1] on javax.swing.JPanel[,0,0,934x612,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.LineBorder@cc0e01,flags=9

Show video to JPanel

落爺英雄遲暮 提交于 2019-12-21 19:48:22
问题 I am creating a simple video player but I'm having problem to show the video file to stream in JPanel. I've created and designed a JFrame and put a square size JPanel inside the form. Here is my codes so far: package SoundsTrip; import java.awt.BorderLayout; import java.awt.Component; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; import javax.media.CannotRealizeException; import javax

Place components at arbitrary (x,y) coordinates

蓝咒 提交于 2019-12-21 09:06:47
问题 I want to place some buttons in a JPanel at random positions (x,y), and these layout classes are annoying. Is this even possible in Swing? 回答1: You can set the coordinates if you use a null layout: panel.setLayout(null); Button b = new Button(....); panel.add(b); b.setSize(width, height); b.setLocation(x,y); But it is strongly recommended to use layouts. Layout classes are not "annoying", they are your friend if you understand them properly. I propose reading a tutorial about GridBagLayout,