jpanel

How to centre the Buttons in my JFrame?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 16:44:33
I am trying to make a board game, I have Player 1 label and player 2 label set to the east and west. I am having trouble centre my 3 x 10 buttons. And is there any simpler way of making all 30 buttons at once? Below is my Code: JPanel panel = new JPanel(); JButton button1 = new JButton();JButton button2 = new JButton(); JButton button3 = new JButton();JButton button4 = new JButton(); JButton button5 = new JButton();JButton button6 = new JButton(); JButton button7 = new JButton();JButton button8 = new JButton(); JButton button9 = new JButton();JButton button10 = new JButton(); JButton button11

Java Swing: Awfully slow cursor response when hovering over rectangles

血红的双手。 提交于 2019-12-08 13:22:38
问题 Below is code where a user is moving the mouse cursor over a bunch of rectangles and the cursor is supposed to change to a hand cursor while over the rectangles and revert to a default normal cursor when not on top of the given rectangles. Problem: The solution works,but painfully slow.They are many ways "to skin a cat", therefore we can model the question in many variants and solutions could be of all kinds, but what is constant, is that we have to loop over each rectangle using an iterator

How to make 3 images fade in and fade out in JPanel?

情到浓时终转凉″ 提交于 2019-12-08 09:12:15
问题 My question is how do i make first image dissappear then sec image come in the it vanish then come the third image. i tried to alter here and there but nothing work. it all come out at once. can someone tell me which part should i alter? import java.awt.AlphaComposite; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing

Layering many JPanels and adding them on the fly

醉酒当歌 提交于 2019-12-08 08:15:30
问题 I'm developing a sim game based on Theme Hospital, which is quite an old game. I've made lots of progress on the underlying workings, however now I am coming to the GUI elements, which I haven't done alot of before. I am still rather new to java. The effect I am trying to create is like shown here... http://www.tubechop.com/watch/18438 Click on a button, opens up a panel with tabs to select from different selections, and then click a button to build a room. I believe for the "tabs" I can use

Put JLabel on Component in JPanel

元气小坏坏 提交于 2019-12-08 08:12:46
问题 I have JPanel which contain a component imageWindow(object of this) now i want to put a label tag in the center of this imagewindow but i am not able to do so? JPanel imagePanel = new JPanel(); imagePanel.setLayout(new GridBagLayout()); imagePanel.add(ic); //ic is imageWindow obj JLabel l1=new JLabel("First Label."); JPanel example =new JPanel(); example.add(l1); imagePanel.add(example); what i am doing wrong here is screenshow i need to put the label here. i want to put the label at the

Java Swing: JButton creates new JTextField(s)

有些话、适合烂在心里 提交于 2019-12-08 07:26:54
问题 Hello :) I am beginner in Java Swing and I can't google solution for my problem. I have a JPanel and want to add JTextField(s) dynamically after pressing a JButton. And how can I getText() from them later? My code, commented part isn't working properly. Variable 'counter' counts how many fields I have in panel. public class AppPanel extends JPanel { private JTextField tfData[]; private JButton btAdd; private int counter = 1; public AppPanel() { setLayout(null); //tfData[counter] = new

how to add Image in JPanel

假如想象 提交于 2019-12-08 06:28:09
问题 I add a tabbedpane in my frame and call tab.add(" ",new Img()) that extends Img with JPanel .. The question is: Could I add JScrollPane in that JPanel and drawImage as JPanel's background and also to do additional drawing on that image such as making route on background image(such as map) because I want to apply Prim's algorithm on those route... And also if I wish to add additional panel on tabbedpane like above, how could I control those tab actions.. The sample code is like that... If you

Making a JPanel Popup

最后都变了- 提交于 2019-12-08 05:14:09
问题 I'm developing an app for computer, and i have a JFrame with a lot of JPanel on it, and when i click on a button, i want another JPanel to popup. Example: When i click on this button http://i62.tinypic.com/c2fzr.jpg I want this window to popup http://i62.tinypic.com/2qi0in7.jpg I already tried making a popup menu, but i don't want a menu, i want a window, and i can't seen to find out how to do it :( It's probably easy, but i don't have enough knowledge in java Any help? thanks guys! 回答1: Ok

Insert JTextArea into a JPanel with a JLabel

最后都变了- 提交于 2019-12-08 05:13:47
问题 I am trying to display the drawing that I have posted. When my code runs and the user clicks Account, the panel only displays the buttons "OK" and "Cancel" (see screenshot). I have added three JTextAreas with a JLabel for each to the panel accountPanel but they don't display. My code is below. import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.Component; import java.awt.LayoutManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax

Clear window from drawing objects

核能气质少年 提交于 2019-12-08 04:30:16
问题 I have 4 classes: Draw, Rectangle (extends Draw), FreeHand (extends Draw) and a test class. I add rectangles and lines drawn by free hand to an arrayList. I have a menubar with choices Back and Clear. Back removes the last drawn object. It is done by removing the last object in the arraylist. Clear clears the windows. It is done by clear the arraylist from all items. Now to my problem: The window does not clear. I don't know how to write the code to make it repaint properly so that the items