layout-manager

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

Android StaggeredGridLayoutManager offset bug

我的梦境 提交于 2019-12-04 12:18:33
问题 When you clear your adapter and call notifyDataSetChanged() - StaggedGridLayoutManager manager still has mCachedStart/End in Span[] instances. So when you add new items to adapter - layout manager draws items with offset , and this is a huge problem . EtsyStaggeredGridView has method resetToTop() which clears all cached stuff and draws everything from scratch. There are some workarounds: Call layoutManager.onDetachedFromWindow(recyclerView, null) after clearing an adapter Set new layout

Java Importing org-jdesktop-layout in Netbeans

こ雲淡風輕ζ 提交于 2019-12-04 08:53:04
I have added the org-jdesktop-layout.jar to my libraries in my netbeans in my project. I found this .jar file in: C:\Program Files\NetBeans 7.0.1\platform\modules However the following line of code is still not recognized: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); I think I am missing the right import statement. What is the right import statement? If there is any other information that would be useful, let me know! Also what determines the prefix for an import statement? EDIT : The following code seems to be from an older GUI library. I

JScrollPane not appearing on JTextArea

ぃ、小莉子 提交于 2019-12-04 06:59:22
问题 I'm trying to add the JScrollPane to my JTextArea, but somehow, it won't appear. I've tried resizing it according to the dimension of the JTextArea, but it doesn't seem to work. Also, notice that I'm using the null layout because I want the full-on flexibility of displaying certain buttons and panels at a pinpoint location. import java.awt.Dimension; import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JScrollPane;

Unusual gaps while using JSeperator - Java

六月ゝ 毕业季﹏ 提交于 2019-12-04 06:40:59
I have been working on a Swing GUI and getting some unusual and unwanted gaps after adding JSeperator , Any idea how to remove them? Or any other option to how to achieve this nicely! Visual Description Gaps are apparent before JLabel "Speed" and after JSlider . Related Code control.setLayout(new BoxLayout(control, BoxLayout.X_AXIS)); ...another code omitted... control.add(orientation); //JLabel control.add(norm); //JRadioButton control.add(back); //JRadioButton control.add(new JSeparator(SwingConstants.VERTICAL)); control.add(speedLabel); //JLabel control.add(speed); //JSlider control.add(new

Java layout center with two panels

99封情书 提交于 2019-12-04 06:30:37
问题 In Java, when using the BorderLayout, is it possible to have two panels in the CENTER, but both be visible on the form. Here is my code: guiFrame.add(guiFieldsPanel, BorderLayout.CENTER); guiFrame.add(guiButtonsPanel, BorderLayout.CENTER); guiFrame.setVisible(true); In the above code, both panels are set to the center, yet I can only see the guiButtonsPanel as it is 'on top' of the guiFieldsPanel. Can i group both panels together, and then set them to be displayed in the CENTER? 回答1: See the

Add a scroll bar to text area

隐身守侯 提交于 2019-12-04 05:20:19
问题 I use Eclipse Window Builder. When I click the button, something will be written on the screen. But since my prints are long, I want to use a scroll pane. public class uyg2 extends JFrame { private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { uyg2 frame = new uyg2(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public

Centering JLabels inside JPanels

眉间皱痕 提交于 2019-12-04 04:23:38
问题 I'm making a score-keeping program, but I'm running into a problem. What I've tried to do is have a JPanel at the top that contains two JPanels, which, in turn, contains two team names. I'm confused as to why the two JLabels at the top of the program aren't centered inside of the JPanels they're contained in. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ScoreFrame extends JFrame { private static final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit()

Java GUI button's label can't be seen

℡╲_俬逩灬. 提交于 2019-12-04 04:00:59
问题 I'm a second year student and I'm working on my OOP project (Calculator). I'm done with the functions of the numeric buttons and operators. Now I'm in the stage of re-arranging my buttons. At first, I just set my button size to (50,50), it works fine and its label is still visible, but when I decided to make it smaller (30, 30), its label turned into "..." instead. Here's the pic: And heres my code: lblEdit.setBounds(-138,-5,180,50); lblView.setBounds(-90,-5,180,50); lblHelp.setBounds(-40,-5

Get height of multi line text with fixed width to make dialog resize properly

孤街醉人 提交于 2019-12-04 03:49:58
I want to create a dialog that contains some kind of text element (JLabel/JTextArea etc) that is multi lined and wrap the words. I want the dialog to be of a fixed width but adapt the height depending on how big the text is. I have this code: import static javax.swing.GroupLayout.DEFAULT_SIZE; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class TextSizeProblem extends JFrame { public TextSizeProblem() { String dummyString = ""; for (int i = 0; i < 100; i++) { dummyString += " word" + i; //Create a long text } JLabel text = new JLabel();