jpanel

How to have Collapsable/Expandable JPanel in Java Swing

帅比萌擦擦* 提交于 2019-12-04 18:42:19
问题 I want a JPanel that can be Collapsed or Expanded when user clicks on a text/icon on its border. I need this type of panel due to space crunch in my application. I read about CollapsiblePanel class but not sure how to use it.. I think SwingX is needed to be downloaded but did not find that anywhere. Moreover, it would be better if I get the solution to this in basic Java Swing. 回答1: not sure where you looked, but it's not that difficult to find - even given the infrastructure mess we are in ;

How to add padding to a JPanel with a border

霸气de小男生 提交于 2019-12-04 16:29:40
问题 I want to add padding to some JPanel s. I found this answer: https://stackoverflow.com/a/5328475/1590323 It worked fine for a panel without a border. But how do I do it for a panel that already has a border? (A TitledBorder in this case) I tried: JPanel mypanel = new MyPanel(); // Panel that I am going to add a TitledBorder to, but needs padding mypanel.setBorder(new EmptyBorder(10,10,10,10)); JPanel mypanel_container = new JPanel(); TitledBorder border = BorderFactory.createTitledBorder

Two Different Panels in One Frame - Java

不打扰是莪最后的温柔 提交于 2019-12-04 15:47:16
I have a question. I have one main frame, and to the left i have a sidebar with menus. My question is, is it possible to make another panel within the main frame, so that if menu1 is clicked, the related contents should be displayed to the second half of the main frame, and when other menus are pressed then obviously the relevant stuff according to what is selected. its a bit hard to explain, sorry. Has anyone got an idea, whether that is possible in Java with Eclipse? yes this's pretty possible you have look at CardLayout , this LayoutManager could be provide the simple way how to implement

How to reset a JTable

家住魔仙堡 提交于 2019-12-04 15:34:15
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 exists. I used revalidate() , reinstantiate() , etc, but of no use. How do I make it work? Assuming

How can I replace one JPanel with another JPanel in the same position?

試著忘記壹切 提交于 2019-12-04 14:49:12
I have a JFrame with about four frames. After a given action I want to replace one panel with another in the same position. My method for switching them looks like this (the this object is a class which extends JFrame ): public void switchPanel(){ mainPanel.remove(introPanel); mainPanel.add(questionPanel); this.repaint(); } The original creation of the window looks like this: mainPanel.add(titlePanel); mainPanel.add(sidePanel); mainPanel.add(introPanel); You ask: How can I replace one JPanel with another JPanel in the same position? Very easily: use a CardLayout as this tool was built for just

MouseEvent lost in JScrollPane

守給你的承諾、 提交于 2019-12-04 14:44:56
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,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=880,height=630]] If now I change panel1.add

How to reload a JPanel?

蹲街弑〆低调 提交于 2019-12-04 09:04:58
I'm a java newbie... I need to know how to reload a JPanel ? I extended the JPanel class and created a panel that will run in a cardlayout in an Applet. I want this panel to reload/refresh after the user clicks a button in this panel. I tried including the revalidate () and repaint () methods (methods I don't understand well) in the ActionListener for the button but nothing happened. Can anyone throw some light on how to correctly refresh the whole panel? This works fine for me. But after an other _panel.revalidate(); _panel.repaint(); 来源: https://stackoverflow.com/questions/17608421/how-to

Difference between JPanel, JFrame, JComponent, and JApplet

允我心安 提交于 2019-12-04 07:30:24
问题 I'm making a physics simulator for fun and I was looking up graphics tutorials when I tried to figure out the difference between all these J's. Can somebody elaborate on them or perhaps provide a link to a helpful source? 回答1: Those classes are common extension points for Java UI designs. First off, realize that they don't necessarily have much to do with each other directly, so trying to find a relationship between them might be counterproductive. JApplet - A base class that let's you write

How do you create a gradient for JPanel? Also, how do you call a class within a class in Java?

不羁岁月 提交于 2019-12-04 07:14:43
问题 I am making a Java GUI and I have searched the internet for 2 hours on how make a gradient for a JPanel. The code below is that I have, but when run the gradient does not show. What is wrong? I've tried many other posts from similar questions on this throughout the Internet but they don't work. I've tried numerous versions, but I also don't exactly know how to run a class within a class. Can someone help me please? class TestPanel extends JPanel{ @Override protected void paintComponent

SetVisible(false) changes the layout of my components within my Panel

萝らか妹 提交于 2019-12-04 06:55:08
How do I make the subpanels within my main panel stay where they are when I set one of the subpanels to be invisible? What I have looks like: [ (Panel1) (Panel2) (Panel3) (Panel4) ] When I do panel3.setVisible(false) it then looks like: [ (Panel1) (Panel2) (Panel4) ] I would like it to look like: [ (Panel1) (Panel2) (Panel4) ] I am using the GridBagLayout and my mainPanel declaration looks like: final JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); and I add an new panel like: final JTextField valueTextField = new JTextField(); valueTextField