Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is fairly simple. It involves dynamic calculation of differences between your pages dimensions and the using them to force preferred size on you <code>JTabbedPane</code>. I did a quick experiment and it worked. So instead of putting a lot of text here - here is the code. It is not perfect but you should get an idea. Questions are welcome, of course.</p> <pre><code>import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class Test { private static int maxW = 0; private static int maxH = 0; public static void main(String[] args) { final JFrame f = new JFrame(); final JTabbedPane tabs = new JTabbedPane(); tabs.add( createPanel(Color.RED, 100, 100), "Red"); tabs.add( createPanel(Color.GREEN, 200, 200), "Green"); tabs.add( createPanel(Color.BLUE, 300, 300), "Blue"); final Dimension originalTabsDim = tabs.getPreferredSize(); tabs.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Component p = ((JTabbedPane) e.getSource()).getSelectedComponent(); Dimension panelDim = p.getPreferredSize(); Dimension nd = new Dimension( originalTabsDim.width - ( maxW - panelDim.width), originalTabsDim.height - ( maxH - panelDim.height) ); tabs.setPreferredSize(nd); f.pack(); } }); f.setContentPane(tabs); f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); } private static final JPanel createPanel( Color color, int w, int h ) { JPanel p = new JPanel(); p.setBackground(color); p.setPreferredSize( new Dimension(w, h)); maxW = Math.max(w, maxW); maxH = Math.max(h, maxH); return p; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload