layout-manager

How do I keep JTextFields in a Java Swing BoxLayout from expanding?

徘徊边缘 提交于 2019-11-29 11:08:14
问题 I have a JPanel that looks something like this: JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); ... panel.add(jTextField1); panel.add(Box.createVerticalStrut(10)); panel.add(jButton1); panel.add(Box.createVerticalStrut(30)); panel.add(jTextField2); panel.add(Box.createVerticalStrut(10)); panel.add(jButton2); ... //etc. My problem is that the JTextField s become huge vertically. I want them to only be high enough for a single line, since that is all that

java.awt.AWTError: BoxLayout can't be shared [duplicate]

我只是一个虾纸丫 提交于 2019-11-29 09:27:56
This question already has an answer here: BoxLayout can't be shared error 4 answers I have initialized MotePanel, Command Panel and LEDPanel before setting their Layout, then how so am I getting this exception. Please help. Exception in thread "main" java.awt.AWTError: BoxLayout can't be shared at javax.swing.BoxLayout.checkContainer(BoxLayout.java:462) at javax.swing.BoxLayout.invalidateLayout(BoxLayout.java:246) at javax.swing.BoxLayout.addLayoutComponent(BoxLayout.java:279) at java.awt.Container.addImpl(Container.java:1107) at java.awt.Container.add(Container.java:974) at javax.swing.JFrame

Using Java pack() method

随声附和 提交于 2019-11-29 05:22:00
I can't make the pack() method work. I tried several things. My code looks like this at the moment: Class 1: public static void main( String[] args ) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { JavaGui mygui = new JavaGui(); // mygui.setSize(1154, 753); mygui.setVisible(true); mygui.pack(); Class 2: public class JavaGui extends javax.swing.JFrame { public JavaGui() { getContentPane().setLayout(null); .. getContentPane().add(panelLeft); ... getContentPane().add(panelRight); I tried putting the pack method in everywhere, but it's not going to work with this way of

How to get GridBagLayout to respect minimum size of a button or panel?

半腔热情 提交于 2019-11-29 03:53:27
In the following GridBagLayout code, I'm expecting the specified minimum size of JButton btn2 to be respected when the JFrame is resized to be made smaller. But when I make the JFrame smaller, the btn2 gets smaller than its minimum size and then vanishes. Can someone point me in the right direction of what I'm doing wrong? Maybe I have to set the minimum size of the JPanel that contains the buttons? Any help is appreciated, thanks! JFrame frame = new JFrame(); frame.setSize(400,300); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new

Span multiple columns with RecyclerView

浪子不回头ぞ 提交于 2019-11-28 15:43:13
So what I am trying to go for is having a staggered layout but the first item in the list needs to span two columns. The first two rows are also a fixed height. I have everything working except the first item spanning two columns. I am using the RecyclerView.Adapter with the StaggeredGridLayoutManager. Doesn't seem like it is out of the box functionality. I assume I can make a custom layout manager I'm just not sure where to start. I have tried searching but I can't find anything about how to get items to span multiple columns. The image below is what what I am looking for in the list.

Which Swing layout(s) do you recommend? [closed]

走远了吗. 提交于 2019-11-28 15:39:36
There are 8 layout managers in the Java library alone, and then there's a bunch of 3rd party products as well. The other day, I tried to use SpringLayout and... well, it ain't working out for me. See my other question . So... if you have a Swing app to design, and you want your layout just so , what are your preferred layout managers? Any interesting/useful experiences to relate? Update: Yup, sure I'm aware that different LMs are appropriate for different layouts. But I'd expect that most of you use 1, 2 or maybe 3 for most everything you do, or you swear by a single one that's so versatile

How to show different pages from the center element of JFrame (having set to BorderLayout)

為{幸葍}努か 提交于 2019-11-28 14:46:29
import java.awt.BorderLayout; import java.awt.Component; import javax.swing.JFrame; import javax.swing.border.Border; public class GuiController extends JFrame { private CentreFrameController centreFrameController; private CustomerPage customerPage; private LoginPage loginPage; public GuiController(){ centreFrameController=new CentreFrameController(this); setLayout(new BorderLayout()); add(centreFrameController,BorderLayout.CENTER); setTitle("Courier System-Login Page"); setVisible(true); setSize(550,650); setDefaultCloseOperation(EXIT_ON_CLOSE); } } CentreFrameController import java.awt

How to make draggable components with ImageIcon

吃可爱长大的小学妹 提交于 2019-11-28 12:55:42
I'm trying to build a user interface for a chess game. I've used a GridBagLayout filled with JLabels and the chess pieces are ImageIcons of the JLabels . Now I would like to move the pieces by dragging it on the board. Is there a way to do this with ImageIcons ? Or is there a better way to solve the problem? EDIT: here is a sample code. you can notice that you can move the iconImage, but it doesn't "drag" with the mouse. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.GridBagConstraints;

Automatically increasing font size in Swing

£可爱£侵袭症+ 提交于 2019-11-28 12:41:47
I would like to know if there are methods of automatically increasing the font size based on the size of a component. I have this gui here: http://img823.imageshack.us/img823/9140/hz7.png Hovewer if i increase the size of the frame, it becomes like this: http://img259.imageshack.us/img259/6308/eari.png the font size doesn't increase. and i don't have an idea on how to make this work. trashgod Some L&Fs support a sizeVariant , illustrated here with com.apple.laf.AquaLookAndFeel . Alternatively, you can scale the font to fill the space allocated by your chosen layout, as shown here . 来源: https:/

java BoxLayout panel's alignment

白昼怎懂夜的黑 提交于 2019-11-28 11:03:13
I have browsed around and haven't found a solution that specifically tailors to my situation. I have a panel that I display in a dialog box: //create dialog panel JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(headerPanel); panel.add(type1Panel); panel.add(type2Panel); panel.add(type3Panel); panel.add(type4Panel); panel.add(type5Panel); panel.add(type6Panel); int result = JOptionPane.showConfirmDialog(null, panel, "Please enter values.", JOptionPane.OK_CANCEL_OPTION); The size of the last two panels, type5 & type6, are of equal size so they look