layout-manager

Resize the components of the frame in full-screen mode

亡梦爱人 提交于 2019-12-23 15:12:47
问题 I want my frame components to be always adjusted in the screen, regardless of screen size. I draw the frame in my Laptop (small screen) and when I run my application in another machine (jar file) with a big screen the frame components doesn't re-size! How I can make my frame resize it's components when I put the frame in full-screen mode in any machine? Current layout Code package package_MSM; import java.awt.Color; public class MSMGui extends JFrame { private static final long

How to create this grid-like layout with column and row labels?

房东的猫 提交于 2019-12-23 04:59:04
问题 import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.util.*; public class BattleShip { private static ImageIcon image1 = new ImageIcon("cols.png"); private static ImageIcon image2 = new ImageIcon("rows.png"); private static JMenuBar menubar = new JMenuBar(); private static JPanel container = new JPanel(); private static JButton[][] button = new JButton[10][10]; private static JFrame frame = new JFrame("BattleShip"); private static JButton open;

Java - CardLayout show() IllegalArgumentException

ⅰ亾dé卋堺 提交于 2019-12-23 04:51:37
问题 I have a problem with the CardLayout show method So I declare my CardLayout and apply it to my JPanel CardLayout cl = new CardLayout(); panel.setLayout(cl); Then I add a 2 panels into the CardLayout cl.addLayoutComponent(panel, "menuScreen"); cl.addLayoutComponent(panel1, "gameScreen"); I then have a JButton that when is clicked, I show the gameScreen public void mouseClicked(MouseEvent e) { if(e.getSource() == (startGame)) scenechange.show(panel,"gameScreen"); } The only problem is that it

How to move JButtons and JLabels position in a JPanel, JFrame

瘦欲@ 提交于 2019-12-23 03:38:15
问题 I am creating a simple lottery as a practice, I am a beginner of Java. I have achieved almost everything that I want apart from one thing: Moving the different texts and buttons to the position that I'd like them to be. Here is a picture edited in Photoshop describing how I would like it to be: The Lottery currently looks like this after you press the Play button: (As you can see the buttons get shifted to the right in order to make space for the text that is squished in to the left of the

Is there a way to set a layout for JOptionsPane.showOptionDialog?

喜你入骨 提交于 2019-12-23 02:42:16
问题 If the array you are using is, let's say a length of 15, and you want to display them all at once, it shows them side by side in a really long display box: String[] options = {"Option 1","Option 2","Option 3","Option 4", "Option 5","Option 6","Option 7","Option 8","Option 9", "Option 10","Option 11","Option 12","Option 13","Option 14", "Option 15"}; int displayoptions = JOptionPane.showOptionDialog (null, "select one", "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null,

How to absolutely position a JPanel over another JPanel with setLayout(null) and a background image?

ぃ、小莉子 提交于 2019-12-22 17:42:16
问题 I'm working with JFrames in Java, specifically with absolutely positioned elements that need to overlap. I understand that to overlay components, one should make a JPanel (with setOpacity(false); ), and position it with either setBounds(x,y,x2,y2); or setPosition(x,y) & setSize(x,y) . Unfortunately the panels act like CSS's inline-divs ; they take up only the needed amount of room on their line, and do not stack. This is the code I have so far, but it doesn't seem to act like I'd imagine it

How to set position of objects in JFrame?

余生长醉 提交于 2019-12-22 11:17:09
问题 I have Labels and JButtons i want to define the position in JFrame. import java.awt.*; import java.net.InetAddress; import java.net.UnknownHostException; import javax.swing.*; public class GuiFrame extends JFrame { public static void main(String[] args) throws UnknownHostException { JFrame f = new JFrame("This is a test"); f.setSize(400, 150); JRadioButton ButtonServer = new JRadioButton("Server"); JRadioButton ButtonClient = new JRadioButton("Client"); InetAddress thisIp = InetAddress

The JPanel contentpane confusion

我怕爱的太早我们不能终老 提交于 2019-12-22 06:39:18
问题 I am learning Java Swing and I appended a menuBar to the frame. By default this should call jframe.getContentPane().add(child) . When I ran the script the menuBar didn't show up. But the button was at the very top "y=0" if that makes sense. Then I realized my mistake I actually had to put in a menu in the menubar. Then the menuBar showed up. So that got me thinking...is the "menubar" "contentpane" actually 2 panels? It is confusing the hell out of me. Because that acted a lot like a panel.

Java align JLabel in center of JPanel

安稳与你 提交于 2019-12-22 05:24:39
问题 I have a bar at the top of my application that has a number of buttons either side of a JLabel. The button's visibility is dependent upon the current task a user is carrying out and one of the button's text may also change depending on the current state. What I would like to do is have a number of buttons stick to the left of the JPanel, the JLabel's center to be in the very center of the JPanel and the rest of the buttons to be to the right of the JPanel. So far I have managed to get the

Java Importing org-jdesktop-layout in Netbeans

久未见 提交于 2019-12-21 17:34:52
问题 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