layout-manager

Unusual gaps while using JSeperator - Java

我与影子孤独终老i 提交于 2019-12-21 13:40:35
问题 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

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

送分小仙女□ 提交于 2019-12-21 10:11:11
问题 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

Sizing a JScrollPane in a JTabbedPane in a JFrame

馋奶兔 提交于 2019-12-20 07:10:00
问题 I understand from this post Don't Set sizes on a JComponent that you dont set preferred sizes on any component and instead let the layout manager do this for you. My question is, I have a JPanel that I put into a JTabbedPane into a JFrame like this JFrame frame=new JFrame(); JTabbedPane pane=new JTabbedPane(); pane.addTab("Tab 1",new JScrollPane(getJPanel1())); pane.addTab("Tab 2",new JScrollPane(getJPanel2())); frame.setContentPane(pane); Now in this case the JTabbedPane will take the size

Parent container/panel for a CardLayout

孤人 提交于 2019-12-20 05:49:07
问题 How I can get the 'container' panel for any panel in CardLayout . That is, if a panel is a card in another 'container' panel, then how to get reference to this 'container' panel, from the card? Here's what i am doing:- public class LogInPanel extends javax.swing.JPanel implements ActionListener{ /** * Creates new form Panel2 */ private JPanel parentPanel; private CardLayout c1=null; public LogInPanel() { initComponents(); //c1=new CardLayout(); parentPanel=(JPanel)(SwingUtilities

JButton.setBounds(x,y,w,h) doesn't seem to work

十年热恋 提交于 2019-12-20 03:18:01
问题 import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.SwingUtilities; public class SimpleExample extends JFrame { public SimpleExample() { setTitle("Simple example"); setSize(500, 500); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); JButton jb = new JButton("TEST"); jb.setBorderPainted(true); jb.setBounds(5, 5, 1, 1); ---> This line add(jb); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void

Why this code's JTextArea occupies entire JFrame?

两盒软妹~` 提交于 2019-12-20 03:16:38
问题 I expect part of my frame contains the JTextArea but it occupies entirely. I cannot trace the error here. import java.awt.*; import javax.swing.*; public class EchoServer { public static void main(String args[]) { CalcFrame c = new CalcFrame(); CalcTextArea a = new CalcTextArea(); } } class CalcTextArea { JTextArea historyDisplayer = new JTextArea("",50,20); CalcTextArea() { //historyDisplayer.setVisible(true); historyDisplayer.insert("Hello World", 0); Color bg = new Color(23,34,56);

JLayeredPane with a LayoutManager

瘦欲@ 提交于 2019-12-20 02:29:11
问题 The situation: drawing a stack of playing cards, like in the Solitaire game. Nicely stacked. To achieve this, I'm using a JLayeredPane in combination with a custom implementation of the LayoutManager interface. The reason for using a custom LayoutManager is that the stack orientation varies, sometimes the playing cards cover each other completely, sometimes partially, and this logic seems to be a good job for a LayoutManager, because this basically boils down to setting the location of the

FlowLayout not displaying components while GridLayout does?

孤街醉人 提交于 2019-12-20 02:28:14
问题 I'm making an application to act as a hub of some sorts, where the user can store shortcuts to their favorite applications and easily launch them. I'm having some problems with FlowLayout , though. When I use GridLayout , the components display perfectly. When I use FlowLayout , nothing displays at all. GridLayout: FlowLayout: All I have changed is the LayoutManager . When I call getComponentCount , they both respond with 9. I thought this post was pretty long, so I put a snippet of my code

Layout Manager and Positioning

别说谁变了你拦得住时间么 提交于 2019-12-19 18:58:27
问题 how to stick JLabel in GlassPane to rellative, floating coordinates from JProgressBar without using ComponentListener or another listener, is there built_in notifiers in Standard LayoutManagers that can notify about its internal state, and can be accesible for override, instead my attempt with ComponentListener and NullLayout . SSCCE about ComponentListener and with NullLayout import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints;

Layout Manager and Positioning

喜欢而已 提交于 2019-12-19 18:58:06
问题 how to stick JLabel in GlassPane to rellative, floating coordinates from JProgressBar without using ComponentListener or another listener, is there built_in notifiers in Standard LayoutManagers that can notify about its internal state, and can be accesible for override, instead my attempt with ComponentListener and NullLayout . SSCCE about ComponentListener and with NullLayout import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridBagConstraints;