|
| ||||||||||
| Tags: graphical user interface, gui, java, jbutton, programming language, swing |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| JButton must retain its position when resizing
Though I searched the internet and tried, understand how Layouts in Swing work but it does not helped me. I still can not build a simple interface containing a JButton that must keep its distance right and down relative to the main window while resizing thereof. I building my interfaces using Netbeans. Can any one help me with this concept? Any help will be appreciated? Thanks in advance. Last edited by Ash maker : 19-01-2010 at 11:56 AM. |
|
#2
| |||
| |||
| Re: JButton must retain its position when resizing
Hi, I think a BoxLayout should do the trick here for you. Have you tried the BoxLayout method and compiled your code? I think you shoudl add it to the upper left and add a 'glue' and the lower and right a 'strut' of the size that suits you. For more methods regarding your problem can be found with, static methods Box.create. Though I will not recommend it to you. |
|
#3
| ||||
| ||||
| Re: JButton must retain its position when resizing
Hello, This is easiest with NetBeans, you have only to place the button at the place you want. However, personally I would use the BorderLayout (Java is the default layout for a JFrame), you place them down a panel with BorderLayout and FlowLayout-Properties-Alignment = Right, and you add the Button in this panel. Code: jpan.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); jpan.add(jButton1); getContentPane().add(jpan, java.awt.BorderLayout.PAGE_END);
__________________ The FIFA Manager 2009 PC Game |
|
#4
| ||||
| ||||
| Re: JButton must retain its position when resizing
Hello, The above mentioned are correct, you can also use BorderLayout panel and you can change the JButton in the Layout-Properties-Button direction on "After". Code: jpan.setLayout(new java.awt.BorderLayout()); jpan.add(jButton1, java.awt.BorderLayout.LINE_END); getContentPane().add(jpan, java.awt.BorderLayout.PAGE_END); |
|
#5
| |||
| |||
| Re: JButton must retain its position when resizing
Hi, Quote:
Quote:
|
|
#6
| ||||
| ||||
| Re: JButton must retain its position when resizing
Hello, I understand your concern with the Free Design, because it is done with a single click. Look at the code below Code: Public class NewJFrame1 extends javax.swing.JFrame {
Public NewJFrame1() {
great("NewJFrame1");
initComponents();
}
/ / <editor-fold Defaultstate="collapsed" desc="Generated code">
private void initComponents() {
jbut1= new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jbut1.setText("jbut1");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, Layout.createSequentialGroup()
.addContainerGap(317, Short.MAX_VALUE)
.add(jbut1)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, Layout.createSequentialGroup()
.addContainerGap(266, Short.MAX_VALUE)
.add(jbut1)
.addContainerGap())
);
java.awt.Size scrsize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((scrsize.width-408)/2, (scrsize.height-334)/2, 408, 334);
}/ / </ Editor-fold>
Public static void hand(Final String[] args) {
Runnable guitest = new Runnable() {
Public void run() {
new NewJFrame1().setVisible(true);
}
};
/ / GUI must start on EventDispatchThread:
SwingUtilities.invokeLater(guitest);
}
/ / Variables declaration - do not modify
private javax.swing.JButton jbut1;
/ / End of variables declaration
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "JButton must retain its position when resizing" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to handle JButton Click Event in Java Swing | Kungfu Pandey | Software Development | 3 | 20-01-2012 11:13 AM |
| Add actionlistener to JButton | KAMANA | Software Development | 6 | 03-08-2010 10:54 AM |
| JButton to send command to Java console | Fox28 | Software Development | 6 | 21-07-2010 10:03 AM |
| What is the use of JButton class? | Owen Fernandes | Software Development | 5 | 19-02-2010 07:19 AM |
| JButton does not work in java swing | RogerFielden | Software Development | 3 | 15-04-2009 12:49 PM |