jpanel

Dragging a JLabel with a TransferHandler (Drag and Drop)

二次信任 提交于 2019-11-28 10:19:29
I am using a TransferHandler to pass data from a JPanel to a JTextArea as a JLabel (Click somewhere in the left panel to create the JLabel to drag) The transfer of the data works fine, but I'd like to also "show" the JLabel as its being dragged along with the mouse pointer. If you comment out dropLabel.setTransferHandler(new TransferHandler("text")); dropLabel.getTransferHandler().exportAsDrag(dropLabel, e, TransferHandler.COPY); you will see how I want it to look. (but of course then the data won't be transferred). How can I get both the transfer to work and the JLabel to follow the mouse

JPanel keylistener

。_饼干妹妹 提交于 2019-11-28 10:07:14
I am trying to add a key listener that holds a JTabbedPane . It should switch the tabs when ctrl + tab is received. But the keypressed event is never sent I tried adding it to the panel and to the tabbed object - but with no success. Here is my code SwitchTabsListener ctrlTabListener = new SwitchTabsListener(genericTabbedPanel); jMainFrame.addKeyListener(ctrlTabListener); genericTabbedPanel.addKeyListener(ctrlTabListener); Riduidel In a typical fashion, your key event is not intercepted by the correct Swing component. You have to understand that the first component below the cursor will

switching JPanel within main window

半城伤御伤魂 提交于 2019-11-28 09:58:04
问题 I have an application that allows users to select an option and based on the user selection a JPanel is removed from the Component, the new JPanel is added and the component is revalidated see code: if (c != null) { contentPane.remove(c); } c = new AddBookInterface(theLibrary); contentPane.add(c); contentPane.revalidate(); break; c is a Component I have several JPanels that the user can switch between and the switch works properly. However, when I add this JPanel upon user selection the

Gradually accelerate sprite on key pressed; gradually decelerate on key released

拥有回忆 提交于 2019-11-28 09:57:18
问题 I've been trying to figure out how I can gradually accelerate a sprite on key pressed and then once the key is released, gradually slow down to a stop, much like the ship in Asteroids . I would like to do this without any game engine if possible. I searched this up on SO and found related questions, but they did not answer my question exactly in my opinion. What I've thought of so far is: //while the key is being pressed //move by increasing y value //but continue to increase the amount y

Frame and Canvas grow larger than specified

血红的双手。 提交于 2019-11-28 09:42:19
问题 I have no idea why I am getting an extra-large window, this is making me run hoops to fit my sprites in the game-window. The constructor should make it so all the subcomponents fit into eachother, but it seems like there is some extra padding in the canvas or frame. I am having a tough time figuring out what the culprit is. The size of my frame should NOT be larger than 800x600 (OS decoration not included, talking about the containers). Panel: java.awt.Rectangle[x=0,y=0,width=810,height=610]

Drawing an Image to a JPanel within a JFrame

坚强是说给别人听的谎言 提交于 2019-11-28 09:19:14
I am designing a program that contains two JPanels within a JFrame, one is for holding an image, the other for holding GUI components(Searchfields etc). I am wondering how do I draw the Image to the first JPanel within the JFrame? Here is a sample code from my constructor : public UITester() { this.setTitle("Airplane"); Container container = getContentPane(); container.setLayout(new FlowLayout()); searchText = new JLabel("Enter Search Text Here"); container.add(searchText); imagepanel = new JPanel(new FlowLayout()); imagepanel.paintComponents(null); //other constructor code } public void

CardLayout in Java change by action in one of the 'cards'

别等时光非礼了梦想. 提交于 2019-11-28 09:14:08
问题 I am making a simple game using a JFrame . I have made a simple "Start" screen which basically consists of a String and a JButton . I am picking up the button click with the actionPerformed(ActionEvent e) method. I don't know how to change the cards using a button click. This may seem like a simple problem to solve, but the twist comes with this: My main JFrame, my StartScreen and my JPanel where the game takes place are all in separate files. My main file, Virus.java, is where I create the

Java :Add scroll into text area

一个人想着一个人 提交于 2019-11-28 08:59:47
How can i add the scroll bar to my text area. i have tried with this code but it's not working. middlePanel=new JPanel(); middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Display Area")); // create the middle panel components display = new JTextArea(16, 58); display.setEditable(false); // set textArea non-editable scroll = new JScrollPane(display); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //Add Textarea in to middle panel middlePanel.add(scroll); middlePanel.add(display); Thanks After adding JTextArea into JScrollPane here: scroll = new

Trying to embed vlcj media player in a WindowsCanvas inside a JPanel

Deadly 提交于 2019-11-28 08:42:08
问题 I'm trying to play a video using vlcj inside a JPanel but it doesn't work for me. The message exception I am getting is "java.lang.IllegalStateException: The video surface component must be displayable" which is the same problem as in Keep getting an Error "Component must be displayable". The code of the JPanel which contains the canvas and the vlcj player is this: import javax.swing.JPanel; import com.sun.jna.Native; import com.sun.jna.NativeLibrary; import java.awt.Canvas; import java.awt

resizable layout swing when disappears JPanel

放肆的年华 提交于 2019-11-28 08:38:25
问题 I have many jPanel (panelF) that are added in other jPanel(panelB). jPanelF contain jPanelC. I have set the layout to add them as follows: PanelB.setLayout(new BoxLayout(this.PanelB, BoxLayout.PAGE_AXIS)); PanelF panelF1 = new PanelF(); PanelB.add(panelF1); PanelF panelF2 = new PanelF(); PanelB.add(panelF2); I set visible false in jPanelC1. But JPanelF2 preserves distance and not want to make that blank space What I want is that when disappearing JPanelC1. Distance is maintained between the