jpanel

Adding JPanels through a loop

♀尐吖头ヾ 提交于 2020-01-11 11:26:08
问题 Made it work! Thank you guys! The code follows. I used BoxLayout since I thought it'd be ideal for stacking questions one on top of the other, but now I got issues with the layout... When I stack several questions the question panels start overlapping. Any thoughts? panels1 = new MultipleChoice[5]; setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); for(int i=0; i<4; i++){ panels1[i]= new MultipleChoice(); panels1[i].setAlignmentX(CENTER_ALIGNMENT); add(panels1[i]); } setVisible(true); I'm

Painting over the top of components in Swing?

自闭症网瘾萝莉.ら 提交于 2020-01-11 08:25:34
问题 I have a JPanel added to a JViewport , and the panel has several other panels added to it. I'm trying to implement a dragging selection, where you can select more than one component by dragging the mouse. The only problem I'm facing is that the selection rectangle is being painted behind the components added to the main JPanel . How can I paint over the top of them? My structure is as follows: JFrame -> ContentPane -> JLayeredPane -> JScrollPane -> JPanel -> JPanel [] . Design draft for

How do I start optimising my Java code? - CPU is at 100%

冷暖自知 提交于 2020-01-11 07:30:15
问题 i have written an application, but for some reason it keeps peaking at 100%. I ran a profile r on a few of the classes and a report show that isReset() and isRunning() seems to be called alot of times. Do you see anything wrong please inform me. thanks Class 1 is the only class that uses the isReset() code so i hope this helps u guys in detecting the error Class 1 package SKA; /* * ver 0.32 June 2009 * * Bug Fix Release: * * Fixed Array resize * Fixed Red Black Tree delete method * Fixed Red

Why I should use a JPanel?

一笑奈何 提交于 2020-01-11 06:56:05
问题 What's the difference between: public class Test { public static void main(String[] args) { JButton button= new JButton("1"); button.setVisible(true); JPanel panel= new JPanel(); panel.add(button); panel.setVisible(true); JFrame frame = new JFrame(); frame.add(panel); frame.setVisible(true); frame.pack(); } } and public class Test { public static void main(String[] args) { JButton button= new JButton("1"); button.setVisible(true); JFrame frame = new JFrame(); frame.add(button); frame

Passing the click event on one jPanel to another JPanel

我是研究僧i 提交于 2020-01-10 04:47:06
问题 I have one outer panel, in the outer panel I have another jPanel placed on it. if i do a right click on the inner panel, outer panel's right click action should happen. if i do left click on the inner panel, its own inner panel's click action should happen. Is it possible to pass click event from one panel to another panel? 回答1: There are a number issues you need to resolve for this to work. The first is understanding that a mouse event is contextual to the component that created it, in

Add JScrollPane to a JPanel

六眼飞鱼酱① 提交于 2020-01-10 02:08:32
问题 I have this interface to create. I have a problem with the JScrollPane: I declared a JPanel with a Gridlayout(8,1,0,2), I want 8 rows appear in this panel. A row is a JPanel to, I set the size to make the 8 row panels appear in the big panel. If the number of rows pass 8, I get two columns ... I added a JScrollPane but it doesn't appear. Testing button at the place of button, the scrollpane appear but returning to panel it disappear.. How can I do ?? 回答1: I found a solution: package d06.m03;

Prevent Java from repainting the content of a JPanel while updating

社会主义新天地 提交于 2020-01-09 11:58:13
问题 I have a JPanel which contains a lot of child components. While updating\adding new components to the parent JPanel I'd like to prevent it from repainting, how can this achieved? 回答1: Try RepaintManager.currentManager(component).markCompletelyClean(component). It will prevent the component from repainting. You might need to do this after each time you add new components. 回答2: setVisible(false) update setVisible(true) 回答3: you could try by using setIgnoreRepaint(boolean value) but it's a

Prevent Java from repainting the content of a JPanel while updating

我只是一个虾纸丫 提交于 2020-01-09 11:58:08
问题 I have a JPanel which contains a lot of child components. While updating\adding new components to the parent JPanel I'd like to prevent it from repainting, how can this achieved? 回答1: Try RepaintManager.currentManager(component).markCompletelyClean(component). It will prevent the component from repainting. You might need to do this after each time you add new components. 回答2: setVisible(false) update setVisible(true) 回答3: you could try by using setIgnoreRepaint(boolean value) but it's a

Java Applet Panel Refresh

偶尔善良 提交于 2020-01-07 09:03:09
问题 I have a Java Applet that loads a record of a board game from a URL and displays the configuration using a series of panels laid out in a grid and nested in a JPanel. This is a small component of an overall applet with text fields and such for inputs and outputs. When a button is pressed, I want the board to show the next configuration from the record. I figured out a way to do this, but when the button is pressed, the same configuration is shown, but when I scroll up or down, or resize the

Java Applet Panel Refresh

徘徊边缘 提交于 2020-01-07 09:03:02
问题 I have a Java Applet that loads a record of a board game from a URL and displays the configuration using a series of panels laid out in a grid and nested in a JPanel. This is a small component of an overall applet with text fields and such for inputs and outputs. When a button is pressed, I want the board to show the next configuration from the record. I figured out a way to do this, but when the button is pressed, the same configuration is shown, but when I scroll up or down, or resize the